generated from the-collab-lab/smart-shopping-list
-
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.
Merge pull request #39 from the-collab-lab/jo-home-page
Protect routes and create welcome page
- Loading branch information
Showing
6 changed files
with
89 additions
and
21 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Outlet, Navigate } from 'react-router-dom'; | ||
import { useAuth } from '../api/useAuth'; | ||
|
||
const ProtectedRoutes = ({}) => { | ||
const { user } = useAuth(); | ||
const isAuthenticated = user || localStorage.getItem('user'); | ||
return isAuthenticated ? <Outlet /> : <Navigate to="/login" />; // Redirect to login if not authenticated | ||
}; | ||
export default ProtectedRoutes; |
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,33 @@ | ||
import { useAuth } from '../api/useAuth'; | ||
import { useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
function Login() { | ||
const { user, signIn } = useAuth(); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
if (user) { | ||
navigate('/'); | ||
} | ||
}, [user]); | ||
|
||
return ( | ||
<div className="flex justify-center items-center h-screen"> | ||
<div className="bg-black text-white rounded-xl w-11/12 max-w-lg p-8 shadow-xl"> | ||
<div className="flex justify-center items-center mb-6"> | ||
<img src="grocerease-light.png" alt="Shopping app logo" /> | ||
</div> | ||
<div className="flex justify-center items-center h-2/5"> | ||
<div className="flex justify-center items-center bg-pink-500 hover:bg-pink-500 hover:bg-opacity-80 w-2/4 h-1/4 rounded-xl p-2"> | ||
<button type="button" onClick={signIn}> | ||
Sign In | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default Login; |