-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from Aymanhki/Vishal
- Loading branch information
Showing
2 changed files
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
// Utility function to get the "epoch_session_id" cookie | ||
export function getSessionCookie() { | ||
return document.cookie.split('; ').find(row => row.startsWith('epoch_session_id=')); | ||
} | ||
|
||
// Utility function to check if the session is active based on the "epoch_session_id" cookie | ||
export function isSessionActive() { | ||
return !!getSessionCookie(); | ||
} | ||
|
||
const ProtectedRoute = ({ children }) => { | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
// Check if the session is active; if not, redirect to the login page | ||
if (!isSessionActive()) { | ||
navigate('/epoch/login'); | ||
} | ||
}, [navigate]); | ||
|
||
// Render the children if the session is active | ||
return children; | ||
}; | ||
|
||
export default ProtectedRoute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters