Skip to content
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

React Navigation #1

Open
oskar-gmerek opened this issue Sep 8, 2021 · 1 comment
Open

React Navigation #1

oskar-gmerek opened this issue Sep 8, 2021 · 1 comment

Comments

@oskar-gmerek
Copy link

Im trying to use it with React Navigation

import { AuthProvider, useAuth } from './auth';
const { status, userToken } = useAuth();

<AuthProvider>
    <ApolloProvider client={client}> 
    <NavigationContainer>
      <Stack.Navigator>      
    {userToken == null ? (
      // No token found, user isn't signed in, login screen should be showed
      <Stack.Screen name="SignIn" component={SignInScreen} />
    ) : (
       // User is signed in, so should see Home Screen
      <Stack.Screen name="Home" component={HomeScreen} />
    ) 
      }
      
  </Stack.Navigator>
      </NavigationContainer>  
      </ApolloProvider>
      </AuthProvider>

I also display on both screens userToken content.

I see that content of userToken is changing (content jwt token after login, a null after log out), but screen is always the same.
Can you help me with that?

Kind Regards,
Oskar

@yjose
Copy link
Member

yjose commented Sep 12, 2021

you can't use useAuth at the same level as AuthProvider to make sure the useAuth will return the correct values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants