ios - 无需注册的 iOS Firebase OTP 验证
问题描述
我需要帮助使用 Firebase 验证 OTP。我设法收到带有 OTP 的短信,但是当我验证它时,我会自动注册,而且我只知道我注册后 OTP 是否有效 - 否则我会收到类似“无效 otp”的弹出窗口。如何手动验证 otp?我的目标是打开另一个屏幕,用户可以在其中输入更多信息。
func verifyCode(){
let credential = PhoneAuthProvider.provider().credential(withVerificationID: self.CODE, verificationCode: code)
print(credential)
loading = true
//here i just want to verify my OTP without signing in...
Auth.auth().signIn(with: credential) { (result, err) in //here i am signing in...
self.loading = false
if let error = err{
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.error)
self.code = ""
self.errorMsg = error.localizedDescription
withAnimation{ self.error.toggle()}
return
}
self.gotoRegistration = true
withAnimation{self.status = true}
}
}
解决方案
如果不自动登录用户,就无法使用 Firebase 身份验证的电话/OTP 提供商。
但用户登录 Firebase 的事实并不意味着您必须授予他们访问您应用中所有部分/数据的权限。如果您希望他们提供更多信息,您可以在他们登录 Firebase 之前或之后这样做,并就用户而言,使其成为同一注册流程的一部分。
所以像:
// Sign the user in with Firebase
// Check if the user has provider the additional registration information
// If not, send them to the registration information screen
// If so, send them to the next screen of the app
您还可以在后端代码中或(如果您使用 Firebase 的后端服务之一)在服务器端安全规则中强制执行这些规则。
推荐阅读
- eclipse - Eclipse Photon 和 Ubuntu 18.04 - DLTK 索引不起作用
- mysql - Magento MySql: ERROR 1005 (HY000) at line 1003: Can't create table 'magento.xxxxxx' (errno: -1)
- python - 无法在 jupyter 中导入名称 cbook
- xml - 如何使用 XmlSlurper 将所有子标签作为列表获取
- json - 如何使用 jq 从 json 对象中修剪子对象?
- c - c中声明和定义的内存分配
- reactjs - 在鼠标悬停时更改内联颜色(React)
- c - 在鼠标事件上重新启动无限循环?
- complex-event-processing - Esper EPL 中的计数和时间窗口
- amazon-web-services - 如何在 AWS 上永久运行 artisan 服务器