Make this redirect back when logged in
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
'use client'
|
||||
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
import { getCookie, setCookie } from '@/util/cookie'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Suspense, useEffect, useState } from 'react'
|
||||
import { HomeButton } from '@/app/components/HomeButton'
|
||||
import { DiscordButton } from '@/app/components/DiscordButton'
|
||||
import axios from 'axios'
|
||||
|
||||
export default function AccountLoginPage () {
|
||||
function LoginForm ({ redirect }: { redirect: string | null }) {
|
||||
const [loading, setLoading] = useState<boolean>(true)
|
||||
const router = useRouter()
|
||||
|
||||
@@ -51,7 +51,7 @@ export default function AccountLoginPage () {
|
||||
if (result.data.data.id)
|
||||
setCookie('accountId', result.data.data.id)
|
||||
|
||||
router.push('/account')
|
||||
router.push(redirect ?? '/account')
|
||||
} else {
|
||||
alert(
|
||||
'Failed to login, error: ' + (result.data.message || 'n/a')
|
||||
@@ -92,3 +92,20 @@ export default function AccountLoginPage () {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function LoginPage () {
|
||||
return (
|
||||
<Suspense
|
||||
fallback={<p className='px-8 -mt-2 -mb-2 text-center'>Loading...</p>}
|
||||
>
|
||||
<LoginPageWithParams />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
|
||||
function LoginPageWithParams () {
|
||||
const params = useSearchParams()
|
||||
const redirect = params.get('redirect')
|
||||
|
||||
return <LoginForm redirect={redirect} />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user