Make this redirect back when logged in

This commit is contained in:
2026-01-30 21:01:35 -07:00
parent 6b455dd959
commit 368f88b2c2
2 changed files with 22 additions and 5 deletions

View File

@@ -1,13 +1,13 @@
'use client' 'use client'
import { useRouter } from 'next/navigation' import { useRouter, useSearchParams } from 'next/navigation'
import { getCookie, setCookie } from '@/util/cookie' import { getCookie, setCookie } from '@/util/cookie'
import { useEffect, useState } from 'react' import { Suspense, useEffect, useState } from 'react'
import { HomeButton } from '@/app/components/HomeButton' import { HomeButton } from '@/app/components/HomeButton'
import { DiscordButton } from '@/app/components/DiscordButton' import { DiscordButton } from '@/app/components/DiscordButton'
import axios from 'axios' import axios from 'axios'
export default function AccountLoginPage () { function LoginForm ({ redirect }: { redirect: string | null }) {
const [loading, setLoading] = useState<boolean>(true) const [loading, setLoading] = useState<boolean>(true)
const router = useRouter() const router = useRouter()
@@ -51,7 +51,7 @@ export default function AccountLoginPage () {
if (result.data.data.id) if (result.data.data.id)
setCookie('accountId', result.data.data.id) setCookie('accountId', result.data.data.id)
router.push('/account') router.push(redirect ?? '/account')
} else { } else {
alert( alert(
'Failed to login, error: ' + (result.data.message || 'n/a') 'Failed to login, error: ' + (result.data.message || 'n/a')
@@ -92,3 +92,20 @@ export default function AccountLoginPage () {
</div> </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} />
}

View File

@@ -19,7 +19,7 @@ export default function BerryDashSplash () {
const token = getCookie('accountToken', '-1') const token = getCookie('accountToken', '-1')
if (token === '-1') { if (token === '-1') {
router.push('/account') router.push('/account/login?redirect=/game/berry-dash/splash')
} else setLoading(false) } else setLoading(false)
}, []) }, [])