From cac0d539f6a4cd9915fc41977c078868f4af70cc Mon Sep 17 00:00:00 2001 From: fredrir Date: Sun, 27 Oct 2024 18:40:31 +0100 Subject: [PATCH] add try / catch in fetchStoredCredentials --- lib/services/authenticator.dart | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/services/authenticator.dart b/lib/services/authenticator.dart index f6a8522..af751c6 100644 --- a/lib/services/authenticator.dart +++ b/lib/services/authenticator.dart @@ -28,9 +28,15 @@ abstract class Authenticator { /// If none were found, nothing is returned. static Future 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; @@ -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; @@ -54,7 +61,6 @@ abstract class Authenticator { return response; } catch (e) { - // User cancelled login return null; } }