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

View File

@@ -42,11 +42,7 @@ export default function AccountPage () {
> >
Change password Change password
</Link> </Link>
<Link <Link href='/account/login' draggable={false} className='button'>
href='/account/refresh-login'
draggable={false}
className='button'
>
Refresh login Refresh login
</Link> </Link>
<button <button