|
|
@@ -1,5 +1,4 @@
|
|
|
import {FC, ReactNode} from 'react';
|
|
|
-import {Navigate} from 'react-router-dom';
|
|
|
import {LOGIN_PATH} from '@routes';
|
|
|
import {useStore} from 'zustand';
|
|
|
import {userStore} from '@stores';
|
|
|
@@ -7,7 +6,12 @@ import {userStore} from '@stores';
|
|
|
const Auth: FC<{children: ReactNode}> = function ({children}) {
|
|
|
const token = useStore(userStore, state => state.token);
|
|
|
|
|
|
- return <>{token.length ? children : <Navigate replace to={LOGIN_PATH} />}</>;
|
|
|
+ if (!token) {
|
|
|
+ parent ? parent.location.replace(LOGIN_PATH) : location.replace(LOGIN_PATH);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return <>{children}</>;
|
|
|
};
|
|
|
|
|
|
export default Auth;
|