Created
December 11, 2024 18:27
-
-
Save crrobinson14/7732156841a732ec519af963ca74ec47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const AppState = observable({ | |
| isAuthenticated: false, | |
| profile: null as Profile | null, | |
| }); | |
| export const setProfile = action((profile: Profile | null) => { | |
| if (AppState.isAuthenticated && profile === null) { | |
| console.log('[STATE] Logged out'); | |
| AppState.isAuthenticated = false; | |
| AppState.profile = null; | |
| } else if (!AppState.isAuthenticated && session !== null) { | |
| console.log('[STATE] Authenticated', profile); | |
| AppState.isAuthenticated = true; | |
| AppState.currentProfile = profile; | |
| } | |
| }); | |
| export const LoginButton: FC = observer(() => { | |
| const profile = AppState.profile; | |
| return AppState.isAuthenticated ? <button>Log Out ({profile?.first_name})</button> : <button>Log In</button>; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment