Firebase reauthenticateAndRetrieveDataWithCredential问题 [英] Firebase reauthenticateAndRetrieveDataWithCredential problems
问题描述
方法reauthenticateAndRetrieveDataWithCredential
需要credential
.
我尝试了此操作,但它给了我一个错误:
I tried this and it gives me an error:
const user = firebase.auth().currentUser;
const credential = firebase.auth.OAuthCredential;
await user.reauthenticateAndRetrieveDataWithCredential(credential);
await user.updateEmail(email);
return email;
错误消息
reauthenticateAndRetrieveDataWithCredential失败:第一个参数"credential"必须是有效的凭据.
reauthenticateAndRetrieveDataWithCredential failed: First argument "credential" must be a valid credential.
我只有宣誓身份验证(没有电子邮件和密码).因此,我无法弄清credential
firebase的需求.有帮助吗?
I only have oath authentication (no email + password). So I can't figure out what credential
firebase need. Any help?
修改:
由于某些原因,我的firebase.auth.OAuthCredential
或(firebase.auth.AuthCredential
)返回未定义.用户已登录/授权.
For some reason my firebase.auth.OAuthCredential
or (firebase.auth.AuthCredential
) return undefined. User is signedIn/authed.
推荐答案
在Vue.js项目中遇到此问题,我们在其中有一个firebase.js
文件来处理模块导入和导出的const
.
Ran into this issue in a Vue.js project where we have a firebase.js
file that handles module imports and exports of const
.
希望这可以帮助某人在使用类似设置时节省时间.
Hoping this will help someone save time when using a similar setup.
文件:firebase.js
import firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/database'
// Initialize Firebase
const app = firebase.initializeApp(options)
export const fb = firebase
export const auth = app.auth()
export const db = app.database()
export const functions = app.functions()
其他脚本文件中或*.vue
import { fb, auth } from './firebase.js'
...
changePassword() {
if (yourFormValidation == true) {
let user = auth.currentUser
const credentials = fb.auth.EmailAuthProvider.credential(
user.email,
this.current_password
)
user.reauthenticateAndRetrieveDataWithCredential(credentials)
.then(() => {
user.updatePassword(this.new_password)
.then(() => {
console.log('your password was successfully changed.')
})
.catch(error => console.log(error))
})
.catch(error => console.log(error.message))
}
}
我遇到Cannot read property 'credential' of undefined"
...
Where I was running into Cannot read property 'credential' of undefined"
...
仅导入{ auth } from './firebase.js
,然后调用auth.EmailAuthProvider()
.
如何访问在 firebase.auth()上找到的其他类 ...
How to access other classes found on firebase.auth()...
firebase.js
export const fb = firebase
import { fb, auth } from './firebase.js'
编写函数的位置
调用fb.auth.EmailAuthProvider.credential()
或其他需要的类
这篇关于Firebase reauthenticateAndRetrieveDataWithCredential问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!