Skip to content

Commit

Permalink
Update AuthContext.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
bsu3338 authored Jul 31, 2023
1 parent a0a8cbf commit fa87d2a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions client/src/hooks/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,24 @@ const AuthContextProvider = ({
const newToken = event.detail;
setUserContext({
token: newToken,
isAuthenticated: true, // or false depending on your logic
user: user, // assuming you have access to the current user
// don't specify redirect here, as the user should stay on the same page
isAuthenticated: true,
user: user,
});
};

const handleLogout = () => {
logout(); // This should clear user context and do necessary cleanup
};

window.addEventListener('tokenUpdated', handleTokenUpdate);
window.addEventListener('logout', handleLogout);

return () => {
window.removeEventListener('tokenUpdated', handleTokenUpdate);
window.removeEventListener('logout', handleLogout);
};
}, [setUserContext, user]);
}, [setUserContext, user, logout]);


// Make the provider update only when it should
const memoedValue = useMemo(
Expand Down

0 comments on commit fa87d2a

Please sign in to comment.