Skip to content

Commit

Permalink
Refactor ProtectedRoutes component to include error handling for auth…
Browse files Browse the repository at this point in the history
…entication check
  • Loading branch information
waveyboym committed Oct 22, 2024
1 parent e01c7f7 commit f435537
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ const ProtectedRoute = (props: ProtectedRouteProps) => {

useEffect(() => {
const checkAuthentication = async () => {
if(userDetails === null){
const res = await AuthService.pingAdmin();
if (res.status === 200) {
const userDeets = await AuthService.getUserDetails();
setUserDetails(userDeets);
} else {
setUserDetails(null);
try{
if(userDetails === null){
const res = await AuthService.pingAdmin();
if (res.status === 200) {
const userDeets = await AuthService.getUserDetails();
setUserDetails(userDeets);
} else {
setUserDetails(null);
}
}
} catch (error) {
setUserDetails(null);
}
setLoading(false); // Set loading to false after the check is done
};
Expand Down

0 comments on commit f435537

Please sign in to comment.