Skip to content

Session status #188

@wil-gerard

Description

@wil-gerard

Detailed Description

The UserContext Hook currently sends an api endpoint request to /api/user/getuser when the navbar component mounts. This action produces an error in the console anytime a user is not logged in.

@timjacksonm #149

We currently have no way of fetching a user's session status, without also fetching their data.

Context

The current UserContext has a useEffect that attempts to fetch a user's data on initial load. The request passes through authentication middleware, and if unauthenticated, a 401 error is returned that prints to the client-side console. Creating a feature to check a user's authentication status before fetching user data would solve this issue.

Possible Implementation

  • Create an API endpoint checking the request's session state
    • If the user is authenticated:
      Respond { "session" : true }
      Else:
      Respond { "session" : false }
  • Add to UserContext hook
    • An authState passed to the children
    • A useEffect that queries the new session state endpoint
    • If the user is authenticated:
      authState = true && set localStorage item { "session" : true }
      Else:
      authState = false

Metadata

Metadata

Assignees

Labels

featNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions