mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-15 07:54:18 +02:00
Update store/routes
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { Navigate, Outlet, useLocation } from 'react-router-dom';
|
||||
import { useAuthStore } from '../store';
|
||||
|
||||
interface AuthOutletProps {
|
||||
redirectTo: string;
|
||||
}
|
||||
|
||||
export const AuthOutlet = ({ redirectTo }: AuthOutletProps) => {
|
||||
const location = useLocation();
|
||||
const isAuthenticated = useAuthStore((state) => !!state.accessToken);
|
||||
|
||||
if (isAuthenticated) {
|
||||
return <Navigate replace state={{ from: location }} to={redirectTo} />;
|
||||
}
|
||||
|
||||
return <Outlet />;
|
||||
};
|
||||
Reference in New Issue
Block a user