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

Need keep login status even when APP reopen #91

Closed
bigzhu opened this issue Nov 20, 2022 · 2 comments
Closed

Need keep login status even when APP reopen #91

bigzhu opened this issue Nov 20, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@bigzhu
Copy link

bigzhu commented Nov 20, 2022

When APP reopen, always need login, it's so silly.

@marcusrohden
Copy link

marcusrohden commented Nov 22, 2022

You can easily do that by managing the auth status with the Nhost Auth callback to update your app state.

<Your nhost client>.auth
        .addAuthStateChangedCallback((authenticationState) {
      log('AUTH STATUS CHANGED: ${authenticationState.name}');
      _updateLoginStatus();
    });

it takes less than a second for the callback to execute. You can wait for it during a splash screen.

@mhadaily mhadaily self-assigned this Dec 4, 2022
@mhadaily mhadaily added the enhancement New feature or request label Dec 4, 2022
@mhadaily
Copy link
Contributor

You can use the .signInWithStoredCredentials() method on the initial load to ensure the user can log in. Please make sure to catch an error, as this method throw an exception if a silent log in is not possible.

nhostClient.auth
        .signInWithStoredCredentials()
        .then((value) {print('user is signed in $value'})
        .catchError(print);

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

No branches or pull requests

3 participants