首页 > 解决方案 > 如何在 Firebase 中重新授权用户?

问题描述

环境


问题

如何使用密码重新授权已登录的用户?我想做的是如下:

const password = "some-password"
firebase.reAuthorizeUser(password)
  .then(() => console.log("ok"))
  .catch(() => console.log("ng"))

先感谢您。

标签: javascriptfirebasefirebase-authentication

解决方案


你正在寻找reauthenticateWithCredential方法。

const user = firebase.auth().currentUser;

// TODO(you): prompt the user to re-provide their sign-in credentials
const credential = promptForCredentials();

user.reauthenticateWithCredential(credential).then(() => {
  // User re-authenticated.
}).catch((error) => {
  // An error ocurred
  // ...
});

Checkout在文档中重新验证用户。


推荐阅读