Finish refresh login

This commit is contained in:
2026-02-01 16:51:03 -07:00
parent a84b053a1c
commit 14763f72f6
2 changed files with 30 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ import Link from 'next/link'
function AccountLoginForm ({ redirect }: { redirect: string | null }) {
const [loading, setLoading] = useState<boolean>(true)
const [alreadyLoggedIn, setAlreadyLoggedIn] = useState<boolean>(false)
const router = useRouter()
const [username, setUsername] = useState<string>('')
@@ -20,8 +21,10 @@ function AccountLoginForm ({ redirect }: { redirect: string | null }) {
const token = getCookie('accountToken', '-1')
if (token !== '-1') {
router.push('/account')
} else setLoading(false)
document.title = 'Lncvrt Games - Account Login'
setAlreadyLoggedIn(true)
}
setLoading(false)
}, [router])
return (
@@ -29,7 +32,9 @@ function AccountLoginForm ({ redirect }: { redirect: string | null }) {
<HomeButton />
<DiscordButton />
<p className={`px-8 ${loading ? '-my-2' : 'mb-4 -mt-2'} text-center`}>
{loading ? 'Loading...' : 'Lncvrt Games Login'}
{loading
? 'Loading...'
: `Lncvrt Games ${alreadyLoggedIn ? 'Refresh ' : ''}Login`}
</p>
{!loading && (
<>
@@ -54,7 +59,9 @@ function AccountLoginForm ({ redirect }: { redirect: string | null }) {
router.push(redirect ?? '/account')
} else {
alert(
'Failed to login, error: ' + (result.data.message || 'n/a')
`Failed to ${
alreadyLoggedIn ? 'refresh ' : ''
}login, error: ` + (result.data.message || 'n/a')
)
}
} catch (e: any) {
@@ -65,9 +72,17 @@ function AccountLoginForm ({ redirect }: { redirect: string | null }) {
JSON.stringify(e.response.data))
)
} else if (e.request) {
alert('Failed to login, no response from server.')
alert(
`Failed to ${
alreadyLoggedIn ? 'refresh ' : ''
}login, no response from server.`
)
} else {
alert('Failed to login, error: ' + e.message)
alert(
`Failed to ${
alreadyLoggedIn ? 'refresh ' : ''
}login, error: ` + e.message
)
}
}
}}
@@ -92,12 +107,18 @@ function AccountLoginForm ({ redirect }: { redirect: string | null }) {
/>
<button type='submit'>Login</button>
</form>
<p className='my-2 w-60 whitespace-normal text-center text-sm'>
<p
className='my-2 w-60 whitespace-normal text-center text-sm'
hidden={alreadyLoggedIn}
>
Note: You login here with your Lncvrt Games Account. If you played
Berry Dash version 1.8.2 or older, then you login with that account
here. It has been migrated automatically.
</p>
<div className='flex justify-center flex-col gap-2 mt-6 text-center'>
<div
className='flex justify-center flex-col gap-2 mt-6 text-center'
hidden={alreadyLoggedIn}
>
<Link
href='/account/forgot-username'
draggable={false}