mirror of
https://github.com/AmanTahiliani/PeerNotes.git
synced 2026-08-07 19:56:19 -04:00
finish login, logout, session context
This commit is contained in:
14
frontend/src/hooks/sessionRedirect.ts
Normal file
14
frontend/src/hooks/sessionRedirect.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { useEffect, useContext } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { SessionContext } from "../contexts/session";
|
||||
|
||||
export const useSessionRedirect = () => {
|
||||
const session = useContext(SessionContext);
|
||||
const navigate = useNavigate();
|
||||
// Redirect to home if session is defined
|
||||
useEffect(() => {
|
||||
if (session !== undefined) {
|
||||
navigate('/');
|
||||
}
|
||||
}, [session, navigate])
|
||||
}
|
||||
Reference in New Issue
Block a user