Kho*_*Phi 11 javascript firebase firebase-authentication angularfire2
我将非常感谢有关如何在Firebase中重新验证用户的帮助.如果文档没有解释如何使用它,我想知道添加所有这些强大的功能是否有任何意义:
目前,这正是我正在尝试的,而且它无法正常工作.错误如cannot read property 'credential' of undefined
在构造函数中:
constructor(@Inject(FirebaseApp) firebaseApp: any) {
this.auth = firebaseApp.auth();
console.log(this.auth);
}
Run Code Online (Sandbox Code Playgroud)
那么功能
changePassword(passwordData) {
if(passwordData.valid) {
console.log(passwordData.value);
// let us reauthenticate first irrespective of how long
// user's been logged in!
const user = this.auth.currentUser;
const credential = this.auth.EmailAuthProvider.credential(user.email, passwordData.value.oldpassword);
console.log(credential);
this.auth.reauthenticate(credential)
.then((_) => {
console.log('User reauthenticated');
this.auth.updatePassword(passwordData.value.newpassword)
.then((_) => {
console.log('Password changed');
})
.catch((error) => {
console.log(error);
})
})
.catch((error) => {
console.log(error);
})
}
}
Run Code Online (Sandbox Code Playgroud)
Fra*_*len 13
该reauthenticate()方法在firebase.User上调用,而不是在firebase.auth.Auth本身上调用.
var user = firebase.app.auth().currentUser;
var credentials = firebase.auth.EmailAuthProvider.credential('puf@firebaseui.com', 'firebase');
user.reauthenticate(credentials);
Run Code Online (Sandbox Code Playgroud)
更新(2017年7月):
4.0版本的Firebase Web SDK有一些重大变化.从发行说明:
爆炸:
firebase.User.prototype.reauthenticate已被删除有利于firebase.User.prototype.reauthenticateWithCredential.
据我所知,这reauthenticateWithCredential是旧方法的替代品.
| 归档时间: |
|
| 查看次数: |
4698 次 |
| 最近记录: |