luc*_*eer 4 email-verification firebase ios-universal-links firebase-dynamic-links
我正在尝试实现对用户电子邮件的验证(使用电子邮件模板中的默认验证 URL),以及 ActionCodeSetting URL(动态链接)以将用户带回应用程序。我对 Firebase 的 ActionCodeSetting 电子邮件验证应该如何工作感到困惑。我已阅读文档的每个可用页面,但我仍然不清楚如何正确配置“继续 URL”以不抢占和覆盖默认验证 URL。
我做了什么:
这是我已经实现的代码:
var actionCodeSettings = ActionCodeSettings.init()
actionCodeSettings.handleCodeInApp = true
let user = Auth.auth().currentUser
let urlString = "https://blaproject.page.link/zCB4"
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
actionCodeSettings.setAndroidPackageName("com.example.android", installIfNotAvailable:true, minimumVersion:"12")
Auth.auth().currentUser?.sendEmailVerification(with: actionCodeSettings, completion: { (error) in
print("verification email sent")
print("action code setting URL is: \(String(describing: actionCodeSettings.url))")
})
Run Code Online (Sandbox Code Playgroud)
以下是 Firebase 控制台中电子邮件模板的默认验证 URL:
https://blaproject-ea9d6.firebaseapp.com/__/auth/action?mode= &oobCode=
这是上面代码发送的验证 URL:
所以我的问题是,为什么此 URL 不验证用户的电子邮件,然后使用继续 URL(以及关联的域)来触发应用程序打开?它仅触发应用程序打开,而不验证用户的电子邮件。
感谢您提供的任何提示来帮助我理解我不理解的内容:)
当链接触发您的应用程序打开时。oobCode您需要从深层链接中解析。您可以使用 FDL 客户端库来获取深层链接。有关深层链接的格式以及如何解析代码,请参阅以下文档:https ://firebase.google.com/docs/auth/custom-email-handler
获得代码后,您需要使用auth.applyActionCode(code)API 来应用它。这将验证电子邮件。
验证通过后,可以调用user.reload()更新emailVerified用户的属性。如果您使用的是 Firebase 安全规则,您还可以user.getIdToken(true)使用更新后的经过验证的电子邮件强制刷新令牌。
| 归档时间: |
|
| 查看次数: |
4587 次 |
| 最近记录: |