简体   繁体   中英

Firebase email authentication not opening the iOS app upon link click

I'm using Firebase authentication in my app (email, passwordless), and trying to follow these directions .

There are several parts that are particularly confusing:

  1. Part of the code is actionCodeSettings.url = URL(string: "https://www.example.com") -- What exactly should this URL be? Why does it matter in the case of an iOS app where I want the user to tap on the link on their iPhone and for it to launch the app?
  2. It mentions that the App Store ID and the Apple Developer Team ID also need to be specified -- what if my app is not on the app store and only distributed via TestFlight?
  3. It says to You will also need to configure your email action handler domain as an Associated Domain in your application capabilities. By default, the email action handler is hosted on a domain like the following example: APP_ID.firebaseapp.com You will also need to configure your email action handler domain as an Associated Domain in your application capabilities. By default, the email action handler is hosted on a domain like the following example: APP_ID.firebaseapp.com -- What is the APP_ID, is it the same as the Apple ID from the previous step? What is the email action handler domain, and how do I add one?
  4. I tried adding the application:openURL:options: method as seen in the example , but it's never actually called.
  5. What exactly will the flow look like? Eg in the perfect implementation, will Safari ever need to be launched? Which links should my app be able to handle?
  6. How can I verify that I implemented everything correctly and that it's not just redirecting to my app/authenticating incorrectly?
  7. When I use GoogleSignIn, I must call the signInSilently method upon app start to know which user is already signed in. This is an asynchronous method, meaning I probably need to show a spinner. Is there a similar requirement for this authentication method? Or how do I know who is logged in?

1. actionCodeSettings.url

This must be a domain that is listed in Console > Develop > Authentication > Sign-in method > Authorized domains. Otherwise you'll get an unauthorized domain error.

What this is actually doing is deciding what happens when the user taps the link on desktop. Eg you may want to take them to a 404 page, or a page that explains to open up the link on their iPhone.

If you have nothing else to use, you can always grab the foo-xxxx.firebaseapp.com or foo-xxxx.web.app urls as listed in that section, which will show a "site not found" page.

2. TestFlight only

This will work! You can grab your App ID from the iTunes Connect site.

3. Email action handler

Not sure exactly what this step is. APP_ID most likely refers to the foo-xxxx value in the firebase console that you can find in step 1.

However, you probably don't want to use the APP_ID.firebaseapp.com value as suggested. Instead, you want to follow the dynamic links instructions , and under your project's settings in Xcode, you'll see the Capabilities > Associated Domains tab. There you'll want to add applinks:your_dynamic_links_domain which will likely look like applinks:foo.page.link .

4. application:openURL:options: not called

Universal links (eg https://foo.page.link ) that launch your app will never call the openURL method. Instead, you need to implement the continue user activity method , as is also mentioned in the dynamic links instructions

5. Proper flow

If you implement everything correctly, it'll look like this:

  1. The user will get an email with a link of the form https://foo.page.link .
  2. Upon tapping the link, the app will open.
  3. Upon app open, the application(:,continue:,restorationHandler:) method will be called at which point you should call Auth.auth().isSignIn(withEmailLink: link) and then eventually call Auth.auth().signIn(withEmail: email, link: link) .

6. Verification

Try sending yourself the email, and tap the sign in link. Go back to the email and tap it again, it should not work as each code can only be used once.

7. Find out who is logged in

You should be able to find out who is logged in via the synchronous method Auth.auth().currentUser?.email .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM