Firebase Authentication link not working - missing trailing slash?
Solution 1
After debugging the iOS implementation of Firebase Dynamic Links it turns out that the missing slash is explicitly required in code (though I am not sure why). Its absence in the email link seems to be a bug and should probably be fixed in the Firebase backend; I filed a bug report on that. The Firebase console has no option to configure a dynamic link domain to be used for automatically generated sign-in links (instead takes any first from the list of configured domains but somehow without path) so I hope this will be made configurable in the future.
Workaround
I simply changed that code (in my Flutter project it's in Pods/FirebaseDynamicLinks/FIRDynamicLinks.m
) and removed the check for the trailing slash. But I have to repeat it when the dependency is updated and I don't know why the check is explicitly there so it might cause other problems.
Two more hints on debugging your dynamic links
- Check the link itself
Copy the link into the address line of your browser and add &d=1
to get the debug view. It shows errors in a big red box above of the diagram - if there are any.
- Check your iOS configuration
Add these two lines temporarily to your didFinishLaunchingWithOptions
in AppDelegate.m
:
[FIRApp configure];
[FIRDynamicLinks performDiagnosticsWithCompletion:nil];
(you may have to @import Firebase;
)
Run the project in Xcode to see a report like this in the debug console:
---- Firebase Dynamic Links diagnostic output start ----
Firebase Dynamic Links framework version 4.0.8
System information: OS iOS, OS version 14.0.1, model iPhone
Current date 2020-10-02 05:02:39 +0000
Device locale en-US (raw en_US), timezone Europe/Berlin
Specified custom URL scheme is com.domain and Info.plist contains such scheme in CFBundleURLTypes key.
AppID Prefix: XXXXXXXX, Team ID: XXXXXXXX, AppId Prefix equal to Team ID: YES
performDiagnostic completed successfully! No errors found.
---- Firebase Dynamic Links diagnostic output end ----
Solution 2
The links with a custom domain worked fine in Apple Mail but no other email client.
As a temporary solution, you can use a Google-provided domain (e.g. projectname.page.link) to generate sign-in links.
You can track it here.
Solution 3
This seems to have been fix in later firebase sdks, if you look at the PR linked in this github issue (I haven't tested, but I have an older sdk version with the issue)
If you don't want to update your SDK right away, an alternative solution is to not use firebase auto-generated email, and instead provide your own email where you insert the firebase link.
In that case, you can tweak the link before inserting it in the email, and make sure it has a trailing slash.
RobDil
Updated on December 19, 2022Comments
-
RobDil over 1 year
I want to use Firebase email link authentication in my iOS (Flutter) app with a custom domain:
The app requests Firebase Auth backend to send an email to the user. -- works
The user clicks a link in the email and is taken back to the app. -- works
The app processes the payload of that link to perform the sign in. -- does not work
Firebase Dynamic Links do work in general but the link from that particular Firebase auto-generated email is not. Technically the app is brought to foreground but the Firebase Dynamic Link
onLink
callback is not fired. I tracked it down to one tiny trailing slash that is missing in the email's link URL:https://link.mydomain.com?link=https://app.mydomain.com/__/auth/action?apiKey=... (not working) https://link.mydomain.com/?link=https://app.mydomain.com/__/auth/action?apiKey=... (works) -------------------------^
To work around this I tried to add a path suffix to my domain but this gave the same results:
https://link.mydomain.com/app?link=https://app.mydomain.com/__/auth/action?apiKey=... (not working) https://link.mydomain.com/app/?link=https://app.mydomain.com/__/auth/action?apiKey=... (works) -----------------------------^
The worst part of this difference that made it so hard to find is that if you copy the link on iOS or long press it to see a preview, the slash is just silently added in the right place! You can paste the link to the notes app, click it, and it works!
Only when viewing the email's source code you can see that it is actually not there:
When requesting the link, I call
FirebaseAuth.instance.sendSignInWithEmailLink
with these params set:url: 'https://app.mydomain.com', dynamicLinkDomain: 'link.mydomain.com',
The
dynamicLinkDomain
param does not accept a protocol or path.Does anybody know how to...
- make Firebase add this slash to the link when sending the mail?
or
- make Firebase Dynamic Link's
onLink
callback react to clicked links that do not have a trailing slash?
For reference
My Info.plist contains this key:
<key>FirebaseDynamicLinksCustomDomains</key> <array> <string>https://link.mydomain.com</string> </array>
My entitlements file contains this key:
<key>com.apple.developer.associated-domains</key> <array> <string>applinks:link.mydomain.com</string> </array>
apple-app-site-association (https://link.mydomain.com/apple-app-site-association):
{ "applinks": { "apps": [], "details": [{ "appID": "XYZ.com.mydomain.app", "paths": [ "NOT /_/*", "/*" ] }] } }
-
RobDil over 3 yearsI got a response from the Firebase Support Team today. They confirm this bug and will fix it soon but cannot give me a timeline when they are going to do it.
-
Piotr Gawłowski over 3 yearsCan You link reported issue here to track? I am struggling with same issues and want to be aware what is happening there.
-
RobDil over 3 yearsI wish I could - but I have no link. I reported it using the form at firebase.google.com/support/troubleshooter/report/bugs. From their email reply: "I appreciate your thorough analysis here and for sharing your workarounds. This looks to be a bug on our end, however, I can't share any timelines yet on when the fix will be available. We'll be sure to address things though once we've identified the root cause of the issue. For further updates, please keep an eye out on our release notes (firebase.google.com/support/releases)."
-
RobDil over 3 yearsFor me this seems like a bug in the Firebase backend, not in the iOS implementation. So I suppose there is no public issue tracker for that. I filed another very simple bug, got it confirmed in June but still nothing out in production... We should update us here as soon as we find out that a fix has been released?
-
Dpedrinha over 3 yearsWhere? And why?