nhost / nhost-dart

Nhost Dart & Flutter packages
https://nhost.io
MIT License
91 stars 33 forks source link

Need keep login status even when APP reopen #91

Closed bigzhu closed 1 year ago

bigzhu commented 2 years ago

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

marcusrohden commented 2 years ago

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 commented 1 year ago

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);