mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
fix(frontend): distinguish initial authentication state on login page mount
- Add wasUserPresentRef to detect if the user was already authenticated on initial page load. - Guard the useEffect redirect block so that it only redirects automatically if the user was already authenticated when mounting. - Prevent duplicate concurrent router.replace calls from canceling each other when logging in via the form.
This commit is contained in:
@@ -41,6 +41,7 @@ export function LoginPage() {
|
||||
const [loginSuccess, setLoginSuccess] = useState(false)
|
||||
const redirectedRef = useRef(false)
|
||||
const callbackProcessedRef = useRef(false)
|
||||
const wasUserPresentRef = useRef(!!user)
|
||||
|
||||
const resolveRedirectTarget = useCallback(() => {
|
||||
const callbackUrl = searchParams.get('callbackUrl')
|
||||
@@ -71,10 +72,12 @@ export function LoginPage() {
|
||||
}
|
||||
|
||||
if (user) {
|
||||
if (!redirectedRef.current) {
|
||||
redirectedRef.current = true
|
||||
router.replace(resolveRedirectTargetRef.current())
|
||||
setIsCheckingSession(false)
|
||||
if (wasUserPresentRef.current) {
|
||||
if (!redirectedRef.current) {
|
||||
redirectedRef.current = true
|
||||
router.replace(resolveRedirectTargetRef.current())
|
||||
setIsCheckingSession(false)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user