【问题标题】:Firebase UpdateEmail returning updateEmail failed: First argument "email" must be a valid stringFirebase UpdateEmail 返回 updateEmail 失败:第一个参数“email”必须是有效字符串
【发布时间】:2020-04-01 07:34:39
【问题描述】:

我的 vue js 组件中有一个电子邮件字段。当组件加载时,它会获取我在注册期间添加的电子邮件值。但是,当我尝试使用 updateEmail 将我的电子邮件更新为新的 emai 时,它会返回错误 code: "auth/argument-error", message: "updateEmail failed: First argument "email" must be a valid string."。

    <template>
    <div>
    <form @submit.prevent="onUpdateProfile">
    <input type="email" v-model="profile.email" placeholder="Enter Your Email..." class="from-input" />
    <button type="submit">submit</button>
    </form>
    </div>
    </template>

    data() {
        return {
          profile: {
            email: ""
          }
        };
      },


    methods:{
    onUpdateProfile() {
          firebase.auth().onAuthStateChanged(user => {
            if (user) {
                user.updateEmail({
                  email: this.profile.email
                })
                .then(() => {})
                .catch(error => {
                  console.log(error);
                });
            }
       }
    },

created() {
  firebase.auth().onAuthStateChanged(user => {
     if (user) {
       this.profile.email = user.email;
     }
  }
}

【问题讨论】:

    标签: firebase vue.js


    【解决方案1】:

    你可以试试改一下吗

    user.updateEmail({
                      email: this.profile.email
                    })
    

    这个?

    user.updateEmail(this.profile.email)
    

    【讨论】:

    • 更改功能后,我在尝试更新电子邮件时收到此错误----消息:“此操作很敏感,需要最近的身份验证。在重试此请求之前再次登录。”
    • 这是正常的,是对 firebase 的安全测量。为此,您还需要获取用户密码并调用user.reauthenticateWithCredential(firebase.auth.EmailAuthProvider.credential(email, password)) 方法,然后调用更新方法
    • 所以我将删除updateEmail功能并添加此功能--user.reauthenticateWithCredential
    • 不会,但会按顺序调用它们。 user.reauthenticateWithCredential(firebase.auth.EmailAuthProvider.credential(email, password)).then(() =&gt; user.updateEmail(email);) 之类的第一个将执行 reauth 部分,第二个将执行更新
    • 你需要添加它。或者您需要注销用户,然后要求再次登录,以便您可以最近登录来进行更新。
    猜你喜欢
    • 1970-01-01
    • 2021-12-22
    • 2018-08-20
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多