I’m developing a mobile app in Flutter and integrating Auth0 Login.
I have an issue on most devices where, when I open the application, an error pops up that I can’t resolve at the root level, and to move forward, I make a new call to the Login method, and then it gets resolved.
I can’t replicate this on iOS or Android emulators! Everything works fine in development; it’s something that happens when installed on devices from the store.
That is, on the first login attempt, the error appears; if I retry the call, it works fine.
The error on iOS is:
error domain com apple authenticationservices webauthenticationservicesession code=3 the uiwindowscene for the returned window was not in the foreground active state
and on Android:
A change on the Lock Screen security settings have deemed the encryption keys invalid and have been recreated. Please try saving the credentials again
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
loadData();
});
}
Future<void> loadData() async {
try {
await dotenv.load();
final credentials = await ref.read(loginProvider.future);
credentials.fold((failure) {
errorCount++;
if (errorCount <= 3) {
showAuthExpiredSessionAlert(context: context, fn: loadData);
} else {
showAuthErrorAlert(context: context, error: failure, fn: loadData);
}
return;
}, (credential) {
//Redirect home
context.go('/home');
return;
});
} catch (e, stackTrace) {
if (mounted) {
errorCount++;
if (errorCount <= 3) {
showAuthExpiredSessionAlert(context: context, fn: loadData);
} else {
showAuthErrorAlert(
context: context,
error: Failure(e.toString()),
stackTrace: stackTrace,
fn: loadData);
}
}
}
}
As you can see, in the “catch” I show an error message with the retry button, and then the login works correctly 100% of the time.
I haven’t found anything about why this is happening. Any information will be appreciated.