... to have my iOS app tell Firebase to send an email with a link, which when the user opens on their device, causes my app to have an authenticated User object.
@objc func handleFirebaseDynamicLink(_ link: DynamicLink) {
guard let link = link.url?.absoluteString else {
WLog("FirebaseProvider handleFirebaseDynamicLink: WARNING, link had no url")
return
}
guard let email = self.emailAddressLastEntered, Auth.auth().isSignIn(withEmailLink: link) else {
WLog("FirebaseProvider handleFirebaseDynamicLink: WARNING, not a signInWithEmailLink or no emailAddress?")
return
}
ISSUE: For some reason, Auth.auth().isSignIn(withEmailLink:) is returning false, even though the link it is given appears to be correct:
`(lldb) po link
"https://<redacted>.firebaseapp.com/__/auth/action?apiKey=<redacted>&mode=signIn&oobCode=123459g71QBFRozWp4fvi-izDstx9BE2o3zhPc_jZQAAAFiU_tqpg&continueUrl=https://<redacted>/applinks/firebaseprovider/signin"`
I verified that the URLs are whitelisted under firebase console -> Authentication -> Sign In Method -> Authorized Domains
If I ignore this and just call `Auth.auth().signIn(withEmail: email, link: link)`, it crashes with an exception of trying to insert a nil value into an NSDictionary :(
Here is the code i'm calling to generate the email send, which is successful. I get the email and copy the link to the simulator:
let actionCodeSettings = ActionCodeSettings.init()
actionCodeSettings.url = URL.init(string: "https://<redacted>/applinks/firebaseprovider/signin")
actionCodeSettings.handleCodeInApp = true
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
Auth.auth().sendSignInLink(toEmail: emailAddress, actionCodeSettings: actionCodeSettings, completion: { (error) in
if let error = error {
WLog("FirebaseProvider signIn: ERROR on sendSignInLink: \(error.localizedDescription)")
waitingForUserBlock(false)
return
}
self.emailAddressLastEntered = emailAddress
self.signedInBlock = signedInBlock
waitingForUserBlock(true)
})
... and here's the AppDelegate code that gets to the handler:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
DDLogInfo(@"AppDelegate continueUserActivity: %@", userActivity.debugDescription);
BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL completion:^(FIRDynamicLink * _Nullable dynamicLink, NSError * _Nullable error) {
if (error) {
DDLogWarn(@"AppDelegate continueUserActivity: ERROR on handleUniversalLink: %@", error.debugDescription);
return;
}
[FirebaseProvider.shared handleFirebaseDynamicLink:dynamicLink];
}];
return handled;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
if (dynamicLink) {
[FirebaseProvider.shared handleFirebaseDynamicLink:dynamicLink];
return YES;
} else {
DDLogWarn(@"%s, WARNING: openURL returning FALSE because i didn't know the prefix: %@", __PRETTY_FUNCTION__, url.absoluteString);
}
return false;
}
I also made sure to re-download the `GoogleService-Info.plist` file, and I see in there that `IS_SIGNIN_ENABLED` is `YES` as i'd expect.
All help much appreciated.