使用firebase phone身份验证创建用户?

时间:2018-03-12 09:07:03

标签: ios swift firebase swift3 firebase-authentication

enter image description here

我正在使用手机身份验证登录(电话号码和密码)以及注册用户详细信息,如姓名,电子邮件,照片网址,地址,电话号码和密码。通过使用注册电话号码字段请求OTP验证电话号码。成功验证电话号码后,它将转到主页。

建议我注册以创建具有电话号码的用户并使用云端防火墙验证使用OTP请求

1 个答案:

答案 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)
        }