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

后端 未结 1 479
难免孤独
难免孤独 2021-02-15 12:01

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 use

相关标签:
1条回答
  • 2021-02-15 12:24

    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

    0 讨论(0)
提交回复
热议问题