如何使用新的Firebase快速更新电子邮件和密码 [英] How to update both Email and Password with new Firebase in swift

查看:112
本文介绍了如何使用新的Firebase快速更新电子邮件和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google的新Firebase开发应用程序. 而且我在更新用户电子邮件和密码时遇到问题.

I'm developing app with new firebase from google. And I'm having problem with updating user email and password.

这就是我尝试过的.

let currentUser = FIRAuth.auth()?.currentUser

currentUser?.updateEmail(email) { error in
    if let error = error {
        print(error)

    } else {
        // Email updated.
        currentUser?.updatePassword(password) { error in
            if let error = error {

            } else {
                // Password updated.
                print("success")

            }
        }
    }
}

但是在更新密码时会出现这样的错误.

But when updating password this occurs error like this.

"Domain = FIRAuthErrorDomain代码= 17014"此操作敏感,需要最近的身份验证..."

"Domain=FIRAuthErrorDomain Code=17014 "This operation is sensitive and requires recent authentication..."

据我了解,我们必须在更新电子邮件后重新配置用户.

As I know we have to re-configure user after updating email.

我尝试使用此代码从Firebase重新配置.

I tried with this code for re-cofiguring from the firebase.

let user = FIRAuth.auth()?.currentUser
var credential: FIRAuthCredential

// Prompt the user to re-provide their sign-in credentials

user?.reauthenticateWithCredential(credential) { error in
  if let error = error {
    // An error happened.
  } else {
    // User re-authenticated.
  }
}

但这会发生错误

在初始化之前使用的变量凭据"

Variable 'credential' used before being initialed

我知道这是因为我没有初始化'credential'变量,但是我不知道如何解决这个问题.

I know this is because I don't initialize 'credential' variable but I don't know how to fix this to work.

有人知道解决方法吗?

推荐答案

在您进行的编辑中,您没有初始化FIRAuthCredential ...它应该是var credential = FIRAuthCredential()或只是像下面的代码一样使用它

In your edit you didn't initialize your FIRAuthCredential ... it should be var credential = FIRAuthCredential() or simply use it like below code

let credential = FIREmailPasswordAuthProvider.credentialWithEmail(email, password: password)

user?.reauthenticateWithCredential(credential) { error in
   if let error = error {
       // An error happened.
   } else {
      // User re-authenticated.
   }
 }

这篇关于如何使用新的Firebase快速更新电子邮件和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆