Hello, I’m using the auth0_flutter package, and I’m having trouble with the credentials manager. In the documentation it clearly states that the credentials()
method “Retrieves the credentials from the storage and refreshes them if they have already expired.” (docs), but I can’t seem to get it working. I’m receiving the refresh_token
after authenticating and I have set token duration to 30s. Also, I have set the token rotation. But when I invoke the credentials()
I get the same tokens back.
So, am I misunderstanding the credentials()
method? Is it supposed to renew the tokens using the refresh_token
or not?
My code:
Future<void> login() async {
await auth0.webAuthentication(scheme: dotenv.env["AUTH0_SCOPE"]!).login();
_isLoggedIn = true;
notifyListeners();
}
Future<void> logout() async {
await auth0.webAuthentication(scheme: dotenv.env["AUTH0_SCOPE"]!).logout();
_isLoggedIn = false;
notifyListeners();
}
Future<bool> isUserLoggedIn() async {
final loggedIn = await auth0.credentialsManager.hasValidCredentials();
if (loggedIn) {
final credentials = await auth0.credentialsManager.credentials();
print(credentials.expiresAt);
print(credentials.idToken);
print(credentials.accessToken);
print(credentials.refreshToken);
}
if (loggedIn) {
_isLoggedIn = true;
return true;
}
return false;
}
The isUserLoggedIn()
is used only when the app starts to check if the user is already logged in.