ecohabit icon indicating copy to clipboard operation
ecohabit copied to clipboard

Create Private Route Component

Open rcamach7 opened this issue 1 year ago • 4 comments

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 the Routes 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

rcamach7 avatar Jul 28 '23 01:07 rcamach7

Hi!

I would like work on this. Could anyone please guide me?

ramya202000 avatar Aug 09 '23 13:08 ramya202000

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.

lugenx avatar Aug 09 '23 21:08 lugenx

Hello! Please assign this to me

Owobilum avatar Aug 10 '23 08:08 Owobilum

Hello! Please assign this to me

just to clarify, PR already was created by @Owobilum before, I have asked him to leave this comment, this way GitHub allows me to assign this to him.

lugenx avatar Aug 10 '23 19:08 lugenx