繁体   English   中英

用户使用Firebase Auth和Swift验证电子邮件后,如何重定向回我的应用程序?

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

当用户注册我的应用程序时,他们会弹出一个窗口,提示您,请验证您的电子邮件,然后登录。 当用户单击“确定”时,将带他们进入登录页面。 此时,用户应转到“邮件”应用(iPhone)并单击从Firebase发送给他们的链接。 单击此链接当前会打开Safari,并告诉用户该帐户已通过验证,然后用户必须手动返回到该应用程序。 如何验证用户,然后又将他们带回应用程序?

我已经阅读了有关continueURL以及Firebase提供的文档的信息,但它没有任何意义,我对需要做的事情感到困惑。 如果有人可以用更简单的方式解释这一点,将不胜感激。

这是我发送电子邮件的方式:user?.sendEmailVerification(完成:无)

预先感谢您的帮助!

您可以使链接直接将您带到iOS应用程序,但可以通过将handleCodeInApp设置为YES来处理应用程序中的代码。 为简单起见,让我们说明如何首先打开网页中的链接( handleCodeInApp为默认值“ NO ”),验证电子邮件,然后重定向回移动应用程序以继续到达用户的预期目的地。

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.
})

在上述流程中,验证链接将发送给用户。 用户将单击链接。 它将打开预配置的网页,将在其中验证电子邮件。 将显示一个继续按钮,如果该设备上安装了iOS应用,则单击该按钮将重定向回该应用。

您将使用Firebase动态链接来拦截该链接。 在此处了解有关在iOS中配置FDL和处理链接的更多信息:

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

Firebase动态链接将具有带有以下URL的深层链接: https://www.example.com/?email=%@", user.email : https://www.example.com/?email=%@", user.email

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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