javascript - 如何在 firebase 身份验证中为 .reauthenticateWithCredential() 创建凭据参数?

标签 javascript firebase authentication firebase-authentication

要在 firebase auth 中删除/编辑用户信息,您需要最近登录过。这可以通过 .reauthenticateWithCredential() 来完成。我怎样才能在javascript中为此创建凭证(使用电子邮件身份验证)?我尝试过(电子邮件,密码)和({电子邮件,密码}),但没有运气。

代码:

function reauth() {
        const credential = firebase.auth.EmailAuthProvider.credential(user.auth.email, password);

        user.reauthenticateWithCredential(credential).then(function() {
                firebase.firestore().collection('users').doc(uid).delete().then(() => {
                    user.delete().then(function() {
                        navigation.replace("Signup")
                    }).catch(function(error) {
                        console.log(error)
                    })
                }).catch((error) => {
                    console.log(error)
                })
        }).catch(function(error) {
            console.log(error)
        })
    }

最佳答案

这对我有用(Web v9)

import {
  EmailAuthProvider, getAuth, reauthenticateWithCredential,
} from 'firebase/auth';

const onReaAuth = () => {
  const passowrd = "from user input";
  const auth = getAuth();
  const { currentUser } = auth;
  const { email } = currentUser;
  const credential = EmailAuthProvider.credential(email, password);
  
  reauthenticateWithCredential(currentUser, credential)
   .then(() => {
     console.log('done')
    }
 }

关于javascript - 如何在 firebase 身份验证中为 .reauthenticateWithCredential() 创建凭据参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66876714/

相关文章:

javascript - Browserify with jQuery >= 2 产生 "jQuery requires a window with a document"

javascript - 无法在 firebase 中获取对象键

authentication - 无法登录 Bot Framework for Microsoft Teams channel

php - Laravel - 使用用户名、电子邮件或电话登录

javascript - 使用 jquery 将一个 div 的子级绑定(bind)到另一个 div 的子级

javascript - 如何使用 JavaScript 和 Bootstrap 动态添加字段?

javascript - 如何将数组从background.js传递到inject.js(内容)脚本(Chrome扩展)

firebase - 一个域上的多个项目

node.js - 未处理的拒绝 (FirebaseError) : No document to update

python - 如何使用 tripit API 制作独立工具?