How can I redirect back to my app after the user has verified their email using Firebase Auth and Swift?

余生颓废 提交于 2019-12-13 12:13:39

问题


When a user signs up in my app, they get a pop up that says, please verify your email and then login. When the user clicks OK, it takes them to login page. At this point the user should go to the Mail app (iPhone) and click the link that has been sent to them from Firebase. Clicking this link currently opens Safari and tells the user the account is verified, then the user has to manually go back to the app. How can I verify the user AND then also take them back to the app?

I've read up about continueURL and also the documentation that Firebase provides but it just doesn't make any sense and I'm getting confused on what I need to do. If someone can explain how to do this is in simpler terms that would be much appreciated.

This is how I'm sending out the email: user?.sendEmailVerification(completion: nil)

Thank you in advance for your help!


回答1:


you can have the link directly take you to the iOS app but handle the code in the app by setting handleCodeInApp to YES. For simplicity, let's illustrate how to first open the link in the web page (handleCodeInApp is NO which is the default), verify the email and then redirect back to the mobile app to continue to the user's intended destination.

var actionCodeSettings =  ActionCodeSettings.init()
actionCodeSettings.canHandleInApp = false
let user = Auth.auth().currentUser()
// This URL will be the deep link of the FDL. It is useful for
// passing state back to your iOS app to let it know that you were
// verifying a user of email user.email. This is also useful
// in case the user clicks the continue button a non iOS device.
// You should own this link.
actionCodeSettings.URL =
    String(format: "https://www.example.com/?email=%@", user.email)
// This is your iOS app bundle ID. It will try to redirect to your
// app via Firebase dynamic link.
actionCodeSettings.setIOSBundleID("com.example.ios")
user.sendEmailVerification(withActionCodeSettings:actionCodeSettings { error in
  if error {
    // Error occurred. Inspect error.code and handle error.
    return
  }
  // Email verification sent.
})

In the above flow, the verification link will be sent to the user. User will click the link. It will open the provisioned web page where the email will be verified. A continue button is shown which on click, if the iOS app is installed on the device, will redirect back to the app.

You will use Firebase dynamic link to intercept that link. Learn more about configuring FDL in iOS and handling the link here:

https://firebase.google.com/docs/dynamic-links/ios/receive https://firebase.google.com/docs/auth/ios/passing-state-in-email-actions#configuring_firebase_dynamic_links

The Firebase dynamic link will have a deep link with the following URL: https://www.example.com/?email=%@", user.email



来源:https://stackoverflow.com/questions/46992992/how-can-i-redirect-back-to-my-app-after-the-user-has-verified-their-email-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!