Skip to content

Instantly share code, notes, and snippets.

@crrobinson14
Created December 11, 2024 18:27
Show Gist options
  • Select an option

  • Save crrobinson14/7732156841a732ec519af963ca74ec47 to your computer and use it in GitHub Desktop.

Select an option

Save crrobinson14/7732156841a732ec519af963ca74ec47 to your computer and use it in GitHub Desktop.
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