8000 Add user context flow and fix bugs by davisengeler · Pull Request #2 · Vibe-House-LLC/memeSRC · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add user context flow and fix bugs #2

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

Merged
merged 8 commits into from
Dec 11, 2022
Merged

Add user context flow and fix bugs #2

merged 8 commits into from
Dec 11, 2022

Conversation

davisengeler
Copy link
Contributor
@davisengeler davisengeler commented Dec 11, 2022

Description

This PR fixes some bugs and improves the CheckAuth component, but most notably refactors the app to utilize Context for the user. This change simplifies some of the logic we had before and allows any component to access the current user data like this:

import { useContext } from 'react';
import { UserContext } from './UserContext';

// Access user and setUser from the context
const {user, setUser} = useContext(UserContext)

Possible user states from UserContext

  • Loading: user will be null (meaning the context isn't ready to use)
  • Authenticated: user will be the CognitoUser object (a user is authenticated)
  • Unauthenticated: user will be: {username: false} (no user is authenticated)

Notes

We could tidy this up a bit by wrapping the CognitoUser object so it always has a status representing loading, authenticated, unauthenticated, etc. See the refactored CheckAuth component for an example of current usage.

I think it would be a little more readable if we wrap it to provide a standard status column.

@davisengeler davisengeler added the enhancement New feature or request label Dec 11, 2022
@davisengeler davisengeler self-assigned this Dec 11, 2022
Copy link
Collaborator
@AustinWoodard AustinWoodard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davisengeler davisengeler merged commit c450484 into dashboard Dec 11, 2022
@davisengeler davisengeler deleted the davis-dev branch December 11, 2022 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0