From cc23ca55943f26ee3ae280dc9eb3234e08ff38fe Mon Sep 17 00:00:00 2001 From: kyuuseiryuu Date: Tue, 10 Mar 2026 13:46:49 +0900 Subject: [PATCH] feat(logto): handle redirect navigation after successful login - Refactor `useHandleSignInCallback` to return only hook data without an internal callback. - Move redirect logic into a separate `useEffect` to decouple navigation from the callback lifecycle. - Ensure the user is redirected to the saved path or `/user-center` immediately upon authentication. --- src/page/Logto/Callback.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/page/Logto/Callback.tsx b/src/page/Logto/Callback.tsx index 25c8422..3a75768 100644 --- a/src/page/Logto/Callback.tsx +++ b/src/page/Logto/Callback.tsx @@ -1,11 +1,13 @@ import { useHandleSignInCallback } from '@logto/react'; import { Spin } from 'antd'; +import { useEffect } from 'react'; import { useNavigate } from 'react-router'; export const CallbackPage = () => { const navigate = useNavigate(); - const { isLoading, isAuthenticated, error } = useHandleSignInCallback(() => { - // Navigate to root path when finished + const { isLoading, isAuthenticated } = useHandleSignInCallback(); + useEffect(() => { + if (!isAuthenticated) return; const redirect = sessionStorage.getItem('redirect'); if (redirect) { sessionStorage.removeItem('redirect'); @@ -13,8 +15,7 @@ export const CallbackPage = () => { } else { navigate('/user-center'); } - }); - + }, [isAuthenticated]); if (isLoading) { return (