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.
This commit is contained in:
parent
2315503388
commit
cc23ca5594
@ -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 (
|
||||
<Spin spinning>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user