I'm implementing email-link signin for my (android but eventually iOS) Flutter app using Firebase.
I eventually managed to send an email successfully to the user with a dynamic link that opens the app when you click it, however, the dynamic link never gets received in-app (.getInitialLink() is always null)
My main()
function looks like this:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
final PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getInitialLink();
debugPrint('A ${initialLink?.link}');
if (initialLink != null) {
final Uri deepLink = initialLink.link;
if (FirebaseAuth.instance.isSignInWithEmailLink(deepLink.path)) {
debugPrint('A signed in with email link');
}
}
FirebaseDynamicLinks.instance.onLink.listen(
(pendingDynamicLinkData) {
debugPrint('B ${pendingDynamicLinkData.link}');
final Uri deepLink = pendingDynamicLinkData.link;
if (FirebaseAuth.instance.isSignInWithEmailLink(deepLink.path)) {
debugPrint('B signed in with email link');
}
},
).onError((error) {
debugPrint('ERROR: $error');
});
runApp(const App());
}
.getInitialLink()
is ALWAYS null and .onLink
never emits any data of any kind.
Dependencies:
...
- firebase_auth 4.2.10 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 2.7.1 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_dynamic_links 5.0.16 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface]
...
flutter doctor
:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.6, on Manjaro Linux 6.1.12-1-MANJARO, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2022.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
• No issues found!
I've asked in Flutter's dedicated Discord server for seeking help, but due to the nature of that server, all your questions get drowned out and nobody gets answered.
When I tried to search for an answer to this problem on Google I found several GitHub issues on the topic but all of them were regarding iOS and none of them ever reached a definitive answer (they were all closed automatically due to inactivity).
I'm a little tired of debugging these SDKs and it's a real killer to my productivity
If anyone could offer even the tiniest bit of advice it'd be appreciated
Solved it after quite some time
For some reason, the firebase_dynamic_links
started working again, but it still didn't make it past the
if (FirebaseAuth.instance.isSignInWithEmailLink(deepLink.path)) {
check
Turns out deepLink.path
did not include the path parameters like oobCode
(thank you ever so much, VSCode debug tool for helping me find this)
I changed it to a simple deepLink.toString()
and now it works.
Phew