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 { useHandleSignInCallback } from '@logto/react';
|
||||||
import { Spin } from 'antd';
|
import { Spin } from 'antd';
|
||||||
|
import { useEffect } from 'react';
|
||||||
import { useNavigate } from 'react-router';
|
import { useNavigate } from 'react-router';
|
||||||
|
|
||||||
export const CallbackPage = () => {
|
export const CallbackPage = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { isLoading, isAuthenticated, error } = useHandleSignInCallback(() => {
|
const { isLoading, isAuthenticated } = useHandleSignInCallback();
|
||||||
// Navigate to root path when finished
|
useEffect(() => {
|
||||||
|
if (!isAuthenticated) return;
|
||||||
const redirect = sessionStorage.getItem('redirect');
|
const redirect = sessionStorage.getItem('redirect');
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
sessionStorage.removeItem('redirect');
|
sessionStorage.removeItem('redirect');
|
||||||
@ -13,8 +15,7 @@ export const CallbackPage = () => {
|
|||||||
} else {
|
} else {
|
||||||
navigate('/user-center');
|
navigate('/user-center');
|
||||||
}
|
}
|
||||||
});
|
}, [isAuthenticated]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<Spin spinning>
|
<Spin spinning>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user