Pan*_*olo 50 javascript firebase firebase-authentication
新文档中的(不清楚)示例:
var user = firebase.auth().currentUser;
var credential;
// Prompt the user to re-provide their sign-in credentials
user.reauthenticateWithCredential(credential).then(function() {
Run Code Online (Sandbox Code Playgroud)
使用v3 Firebase客户端,我应该如何创建此credential对象?
我试过了:
reauthenticateWithCredential(email, password) (比如登录方法)reauthenticateWithCredential({ email, password }) (文档仅提到一个参数)没运气 :(
PS:我不计算在新文档中搜索相关信息所浪费的时间......我非常想念那些神话般的firebase.com文档,但想切换到v3 for firebase.storage ...
Pan*_*olo 98
我设法让它工作,文档应该更新,以包括这个谁不想花费太多时间在详尽但难以阅读的参考.
凭证对象的创建方式如下:
const user = firebase.auth().currentUser;
const credential = firebase.auth.EmailAuthProvider.credential(
user.email,
userProvidedPassword
);
// Now you can use that to reauthenticate
user.reauthenticateWithCredential(credential);
Run Code Online (Sandbox Code Playgroud)
mau*_*lus 23
完整答案 - 您可以执行以下操作:
var user = firebase.auth().currentUser;
var credentials = firebase.auth.EmailAuthProvider.credential(
user.email,
'yourpassword'
);
user.reauthenticateWithCredential(credentials);
Run Code Online (Sandbox Code Playgroud)
请注意,这reauthenticateWithCredential是更新版本reauthenticate()
使用新的 Firebase 版本 9.*
import {
EmailAuthProvider,
getAuth,
reauthenticateWithCredential,
} from "firebase/auth";
const auth = getAuth();
let credential = EmailAuthProvider.credential(
auth.currentUser.email,
password
);
reauthenticateWithCredential(auth.currentUser, credential)
.then(result => {
// User successfully reauthenticated. New ID tokens should be valid.
})
Run Code Online (Sandbox Code Playgroud)
有多种方法可以重新进行身份验证。请参阅参考文献:https ://firebase.google.com/docs/reference/js/firebase.User
firebase
.auth()
.currentUser.reauthenticateWithPopup(new firebase.auth.GoogleAuthProvider())
.then((UserCredential) => {
console.log("re-outh", UserCredential);
});
Run Code Online (Sandbox Code Playgroud)
如果您的应用程序允许多种身份验证方法,您可能需要首先找出使用的提供者。您可以通过查看firebase.auth().currentUser.providerData数组来做到这一点。
| 归档时间: |
|
| 查看次数: |
14286 次 |
| 最近记录: |