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

梦想的初衷 提交于 2019-12-04 17:07:11

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

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