Skip to content

Commit

Permalink
Fix to clarify to wait for auth process to finish (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaiste authored Jul 7, 2023
1 parent f2eeff4 commit ac1c910
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ReactDOM.render(

const App = () => {
const { login } = useAuth();
const { authenticated, user } = useAuthState();
const { authenticated, user, authenticating } = useAuthState();

const handleSignIn = async () => {
const { data } = await login({
Expand All @@ -70,8 +70,13 @@ const App = () => {
}
};

// Important: wait till the authentication process finishes
if (authenticating) {
return <div>Loading...</div>
}

if (authenticated && user) {
return <span>Signed in as {user.firstName}</span>;
return <span>Signed in as {user.email}</span>;
}

return <button onClick={handleSignIn}>Sign in</button>;
Expand Down

0 comments on commit ac1c910

Please sign in to comment.