Create Private Route Component
Opened this issue · 4 comments
rcamach7 commented
Why?
- When users are logged in, they should not be able to visit certain pages.
- currenlty the redirect happens within each private page. For example, HomePage and Profile component use a hook to check if the user is logged in, and redirects them if not.
- We want to make a component that can be used across all private routes, without making the actual page component worry about this
How?
- Create a
PrivateRoute
component.- It will use userContext to pull user information. If user does not exist, redirect user to the login page. If user exists, allow the page to be displayed
- there are several ways to build this. You can look at this example to get an idea
- Use this
PrivateRoute
on all pages in theRoutes
file that only logged in users should be able to visit - remove the previous logic in these components that used a hook to redirect users
ramya202000 commented
Hi!
I would like work on this. Could anyone please guide me?
lugenx commented
Hey @ramya202000,
Thanks for your interest! This issue is already in a PR and being reviewed.
Feel free to check out other issues or join our Discord to chat and get updates.
Owobilum commented
Hello! Please assign this to me