I was using my website to verify the email of my users but since the email verification from firebase always redirect to the mobile app when you use a smartphone, i have to handle the link in-app.
To do so, i have followed the documentation and i have also read this.
It should be working in theory, the only problem is that the FirebaseDynamicLinks.instance.getInitialLink() only returns the link that opened the app.
Here is my code to validate the email :
final PendingDynamicLinkData? pendingLink = await FirebaseDynamicLinks.instance.getInitialLink();
if (pendingLink != null) {
final Uri deepLink = pendingLink.link;
final String? actionCode = deepLink.queryParameters['oobCode'];
try {
await provideFirebaseAuth().checkActionCode(actionCode!);
await provideFirebaseAuth().applyActionCode(actionCode);
// If successful, reload the user:
getCurrentUser()!.reload();
} on FirebaseAuthException catch (e) {
if (e.code == 'invalid-action-code') {
LogManager.d('The code is invalid.');
}
}
}
90% of the time, the email verification is sent when the user creates his account so he is still in the app and receive a mail, and then he :
- Put the app in background (
pausedstate) - Goes to his mailbox
- Clicks on the link
- Gets redirected back to the app
And unfortunately FirebaseDynamicLinks.instance.getInitialLink() can't work in this situation as the app may not be killed.
Would FirebaseDynamicLinks.instance.onLink work ? Or is there any other way to solve this please ?
PS : I know that there is a possible to add handleCodeInApp: false to the user.sendEmailVerification(codeSettings) to force redirect to the browser, but it simply doesn't work with the latest version of firebase_auth: 3.3.9 and even in older versions so i have to handle it in app. I have made an issue on GitHub about that few months ago already...
There is also an issue regarding FirebaseDynamicLinks that i have made.
EDIT :
To get the bounty, i would like the whole code from sending an email verification, until the checkActionCode call that handles the above use case please + when the app is terminated during the process.
EDIT 2 :
I have reached out Firebase support regarding this as it seems there are few bugs underneath.
Will post an answer once i have a concrete response for what is happening.