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