I have "Email link sign-in (Passwordless)" in my app. It works as expected. But there is one issue that the catchError
on _auth.signInWithEmailLink(email: userEmail, emailLink: link.toString())
is called several times (e.g. if I go to my email, use an expired action code for the 4th time, when it navigates to the app, it opens 4 dialogs for that error).
Here is the code in didChangeAppLifecycleState
void didChangeAppLifecycleState(AppLifecycleState state) async {
FirebaseDynamicLinks.instance.onLink.listen((dynamicLink) {
final Uri? deepLink = dynamicLink.link;
emailLinkService.handleLink(
deepLink!, _emailController.text, context, state);
if (state == AppLifecycleState.paused) {
Navigator.popUntil(context, (route) => !(route is PopupRoute));
}
}, onError: (e) async {
print(e);
});
final PendingDynamicLinkData? data =
await FirebaseDynamicLinks.instance.getInitialLink();
final Uri? deepLink = data?.link;
if (deepLink != null) {
emailLinkService.observableLink = deepLink.toString();
}
}
And here is the handleLink
method:
class EmailLinkService {
final FirebaseAuth _auth = FirebaseAuth.instance;
Future handleLink(Uri link, userEmail, BuildContext context, state) async {
if (_auth.isSignInWithEmailLink(link.toString())) {
_auth
.signInWithEmailLink(email: userEmail, emailLink: link.toString())
.catchError((onError) {
if (state == AppLifecycleState.resumed) {
PlatformAlertDialog(
title: onError.code,
content: onError.message ?? onError.toString(),
defaultActionText: Strings.ok,
).show(context);
}
print(
'>>>> email link service > handleLink > Error signing in with email link $onError');
});
}
}
}
I expect to get one dialog each time when there is an error.