Skip to content

Create Private Route Component #230

@rcamach7

Description

@rcamach7

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

Metadata

Metadata

Assignees

Labels

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions