Skip to content

Commit

Permalink
add try / catch in fetchStoredCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrir committed Oct 27, 2024
1 parent 074d085 commit cac0d53
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/services/authenticator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ abstract class Authenticator {
/// If none were found, nothing is returned.
static Future<Credentials?> fetchStoredCredentials() async {
if (await auth0!.credentialsManager.hasValidCredentials()) {
credentials = await auth0!.credentialsManager.credentials();
loggedIn.value = true;
return credentials;
try {
credentials = await auth0!.credentialsManager.credentials();
loggedIn.value = true;
return credentials;
} catch (e) {
await auth0!.credentialsManager.clearCredentials();
loggedIn.value = false;
return null;
}
}

loggedIn.value = false;
Expand All @@ -43,8 +49,9 @@ abstract class Authenticator {
}

try {
//final scheme = dotenv.env['AUTH0_CUSTOM_SCHEME'];
final response = await auth0!.webAuthentication(scheme: dotenv.env['AUTH0_CUSTOM_SCHEME']).login();
final response = await auth0!.webAuthentication(scheme: dotenv.env['AUTH0_CUSTOM_SCHEME']).login(
parameters: {'scope': 'openid profile email offline_access'},
);
await auth0!.credentialsManager.storeCredentials(response);

loggedIn.value = true;
Expand All @@ -54,7 +61,6 @@ abstract class Authenticator {

return response;
} catch (e) {
// User cancelled login
return null;
}
}
Expand Down

0 comments on commit cac0d53

Please sign in to comment.