Credentials are not returned when trying to login, app gets stuck
Checklist
- [X] The issue can be reproduced in the auth0_flutter sample app (or N/A).
- [X] I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- [X] I have looked into the API documentation and have not found a suitable solution or answer.
- [X] I have searched the issues and have not found a suitable solution or answer.
- [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- [X] I agree to the terms within the Auth0 Code of Conduct.
Description
After logging in with auth0, the credentials cannot be retrieved on Android or the Web (Works for iOS). The warning message, No stored state: unable to handle response appears on the console when the webpage gets stuck and you have to kill the app and relaunch the app to try logging in again.
Initially, I was using the flutter_appauth package for logging in using Auth0 and everything was working fine. Now, I am trying to migrate it to the official Auth0 package i.e. auth0_flutter and it is now working for Android and Web.
Reproduction
- Login function below:
Future<Credentials?> login() async {
try {
if (kIsWeb) {
/// Attempt to login the user with the redirect method
await _auth0Web.loginWithRedirect(
audience: auth0Audience,
scopes: authScopes['auth'],
redirectUrl: auth0RedirectUri);
return await _auth0Web.credentials();
} else {
/// Handle the needed credentials for mobile
Credentials? credentials = await _auth0
.webAuthentication(scheme: 'com.project.portal')
.login(
audience: auth0Audience,
scopes: const {'openid', 'profile', 'email', 'offline_access'},
redirectUrl: auth0RedirectUri,
idTokenValidationConfig: IdTokenValidationConfig(issuer: 'https://$auth0Domain'),
safariViewController: const SafariViewController(),
parameters: {'prompt': 'login'},
);
return credentials;
}
} on Exception catch (e) {
print('Error logging in: $e');
return null;
}
}
- Call above login function on a button click:
ElevatedButton(
onPressed: () async {
final credentials = await login();
setState(() {
_credentials = credentials;
});
},
child: const Text('Login'),
),
Additional context
On Auth0, I have first created a new Native Application. I have created a flutter application that supports iOS, Android, and the Web which uses the same configuration from Auth0. The auth0 domain is a custom domain
Flutter Doctor Output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.9, on macOS 14.1.1 23B81 darwin-x64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc2)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.85.0)
[✓] Connected device (3 available)
[✓] Network resources
• No issues found!
auth0_flutter version
1.3.1
Flutter version
3.13.9
Platform
Android, Web
Platform version(s)
No response
Hi @aakashawalkar, thanks for raising this.
Can you confirm that you can indeed reproduce this on the auth0_flutter sample app?
@Widcket - Yes, I see the same behavior on the sample app.
Thanks. @poovamraj could you please take a look?
Hi @Widcket @poovamraj -
When I tried tweaking the Auth0 configuration, most of the time I saw the below error message
No stored state - unable to handle the response
Also, sometimes, I see below error messages while logging in -
E/flutter (26530): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: a0.sdk.internal_error.unknown: Received error with code a0.sdk.internal_error.unknown
E/flutter (26530): #0 MethodChannelAuth0FlutterWebAuth.invokeRequest (package:auth0_flutter_platform_interface/src/method_channel_auth0_flutter_web_auth.dart:45:7)
E/flutter (26530): <asynchronous suspension>
E/flutter (26530): #1 MethodChannelAuth0FlutterWebAuth.login (package:auth0_flutter_platform_interface/src/method_channel_auth0_flutter_web_auth.dart:21:9)
E/flutter (26530): <asynchronous suspension>
E/flutter (26530): #2 WebAuthentication.login (package:auth0_flutter/src/mobile/web_authentication.dart:82:25)
E/flutter (26530): <asynchronous suspension>
Has any solution been found for this issue? I am in the same situation. Trying to migrate away from flutter_appauth, and it works in iOS but not in Android.
Any workarounds to fix this?