ADD: card component and login behavior
This commit is contained in:
@@ -3,8 +3,15 @@ import { useAuth } from "../components/AuthContext";
|
||||
import type { JSX } from 'react';
|
||||
|
||||
const ProtectedRoute = ({ children }: { children: JSX.Element }) => {
|
||||
const { token } = useAuth() as { token?: string | null };
|
||||
return token ? children : <Navigate to="/" />;
|
||||
// const { token } = useAuth();
|
||||
const token = localStorage.getItem('token');
|
||||
// console.log(token);
|
||||
if(token!=null)
|
||||
return children;
|
||||
else
|
||||
console.log(token)
|
||||
return <Navigate to="/" />;
|
||||
// return token ? children : <Navigate to="/" />;
|
||||
};
|
||||
|
||||
export default ProtectedRoute;
|
||||
|
||||
Reference in New Issue
Block a user