generated from the-collab-lab/smart-shopping-list
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ho list page #36
Merged
Merged
Ho list page #36
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c37e22b
route protection for list and manage list page
IamHenryOkeke 8cd77a8
styled list page
IamHenryOkeke edf575e
refactored code for priate routes
IamHenryOkeke ce98318
fixed styling issue
IamHenryOkeke 3d0bdc5
added code for setting selected list in local storage
IamHenryOkeke 45d12cc
wrapped app in auth provider
IamHenryOkeke c8a9b39
added logic for display selected list across all and logic to clear l…
IamHenryOkeke 40f8d47
added page refresh after sign out
IamHenryOkeke 9289aa9
refactored auth context code
IamHenryOkeke ea62144
deleted context for route protection
IamHenryOkeke 6703049
styled current selected list section
IamHenryOkeke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { createContext, useState, useEffect } from 'react'; | ||
import { onAuthStateChanged } from 'firebase/auth'; | ||
import { auth } from './api/config'; | ||
|
||
export const AuthContext = createContext(); | ||
|
||
export default function AuthProvider({ children }) { | ||
const [currentUser, setCurrentUser] = useState(null); | ||
const [pending, setPending] = useState(true); | ||
|
||
useEffect(() => { | ||
onAuthStateChanged(auth, (user) => { | ||
setCurrentUser(user); | ||
setPending(false); | ||
}); | ||
}, []); | ||
|
||
if (pending) { | ||
return ( | ||
<div className="flex justify-center items-center h-[100vh]"> | ||
Loading.....Please wait | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<AuthContext.Provider value={{ currentUser }}> | ||
{children} | ||
</AuthContext.Provider> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React, { useContext } from 'react'; | ||
import { Navigate, Outlet } from 'react-router-dom'; | ||
import { AuthContext } from '../AuthContext'; | ||
|
||
export default function ProtectedRoutes() { | ||
const { currentUser } = useContext(AuthContext); | ||
return currentUser ? <Outlet /> : <Navigate to="/" />; | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice use of React Context 💫. We already have this code, for fetching and detecting user changes, in the
useAuth
custom hook so this is a duplication. I would recommend to move the pending state/logic to theuseAuth
hook and use the hook here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Reda for pointing that out. I took a closer look at the code and i figured that the using a context wasn't necessary so I removed the context as a whole. The route protection works just fine regardless. Please review