-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Harry Curtis
committed
Aug 16, 2024
1 parent
5904bc5
commit 040b2ea
Showing
11 changed files
with
66 additions
and
72 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
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 |
---|---|---|
@@ -1,26 +1,19 @@ | ||
import { useAuth } from "../hooks/useAuth"; | ||
import { useEffect } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { useAuth } from "../hooks"; | ||
import React, { useEffect } from "react"; | ||
import { Navigate } from "react-router-dom"; | ||
|
||
export const ProtectedRoute = ({ children }) => { | ||
export const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { | ||
const { user, authenticate } = useAuth(); | ||
|
||
useEffect(() => { | ||
const waitThenCheckUser = async () => { | ||
await authenticate(); | ||
|
||
if (!user) { | ||
return <Navigate to="/login" />; | ||
} | ||
}; | ||
|
||
waitThenCheckUser(); | ||
if (!user) { | ||
authenticate(); | ||
} | ||
}, [user, authenticate]); | ||
|
||
return children; | ||
}; | ||
if (!user) { | ||
return <Navigate to="/login" />;; | ||
} | ||
|
||
ProtectedRoute.propTypes = { | ||
children: PropTypes.element, | ||
return children; | ||
}; |
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
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
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
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
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
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
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
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
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