Need keep login status even when APP reopen
bigzhu opened this issue · comments
bigzhu commented
When APP reopen, always need login, it's so silly.
Marcus Rohden commented
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.
Majid Hajian commented
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);