我正在使用手机身份验证登录(电话号码和密码)以及注册用户详细信息,如姓名,电子邮件,照片网址,地址,电话号码和密码。通过使用注册电话号码字段请求OTP验证电话号码。成功验证电话号码后,它将转到主页。
建议我注册以创建具有电话号码的用户并使用云端防火墙验证使用OTP请求
答案 0 :(得分:2)
对于发送Otp使用此方法。 手机号码必须与国家/地区代码Ex。 1 强>
PhoneAuthProvider.provider().verifyPhoneNumber(mobileNo, uiDelegate: nil) { (verificationID, error) in
if let error = error {
print(error)
APPDEL.window?.makeToast("Your mobile number is not valid")
complition(false)
return
}
UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
complition(true)
// Sign in using the verificationID and the code sent to the user
}
验证OTP并成功登录使用此
let verificationID = UserDefaults.standard.string(forKey: "authVerificationID")
let credential = PhoneAuthProvider.provider().credential(
withVerificationID: verificationID!,
verificationCode: verificationCode)
Auth.auth().signIn(with: credential) { (user, error) in
if let error = error {
print(error.localizedDescription)
APPDEL.window?.makeToast("OTP entered is incorrect")
complition(false)
return
}
complition(true)
}