first commit
This commit is contained in:
11
src/ProtectedRoute.js
Normal file
11
src/ProtectedRoute.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import React from "react";
|
||||
import { Navigate } from "react-router-dom";
|
||||
import { getToken } from "utils/tokenService";
|
||||
|
||||
const ProtectedRoute = ({ children }) => {
|
||||
console.log(`token for checking whether authenticated: ${getToken()}`);
|
||||
const isAuthenticated = getToken() !== null; // Check if user is authenticated
|
||||
return isAuthenticated ? children : <Navigate to="/auth/login" replace />;
|
||||
};
|
||||
|
||||
export default ProtectedRoute;
|
||||
Reference in New Issue
Block a user