【问题标题】:Creating user using firebase phone authentication? [closed]使用 Firebase 电话身份验证创建用户? [关闭]
【发布时间】:2018-08-20 06:01:24
【问题描述】:

我正在使用电话身份验证进行登录(电话号码和密码),并使用姓名、电子邮件、照片网址、地址、电话号码和密码等用户详细信息进行注册。通过使用注册电话号码字段请求 OTP 来验证电话号码。成功验证电话号码后,它会进入主页。

建议我注册以使用电话号码创建用户并使用 Cloud Firestore 使用 OTP 请求进行验证

【问题讨论】:

  • 你已经写了所有的概念,现在我们在这里建议什么?
  • @dahiya_boy 是的,我有概念,但我不知道将数据保存在 firebase 并请求 OTP 验证以进行注册

标签: ios swift firebase swift3 firebase-authentication


【解决方案1】:

对于发送 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)
        }

【讨论】:

  • 感谢您的回答,我如何将数据用户名、电话号码、密码插入到 firebase 并请求 OTP 进行验证 - 注册
  • 不能传递所有数据你只能传递手机号码也可以参考这个链接firebase.google.com/docs/auth/ios/phone-auth
  • @PvDev for Auth firebase 为您完成,因此您无需担心。
  • @dahiya_boy 如何在创建新用户之前检查用户的电话号码是否已经在 Firebase 数据库中?
  • @Jaydip 如何在创建新用户之前检查用户的电话号码是否已经在 Firebase 数据库中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-09
  • 2021-07-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多