要在 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/