javascript - Firebase reauthenticateAndRetrieveDataWithCredential 问题
问题描述
方法reauthenticateAndRetrieveDataWithCredential
需要credential
.
我试过这个,它给了我一个错误:
const user = firebase.auth().currentUser;
const credential = firebase.auth.OAuthCredential;
await user.reauthenticateAndRetrieveDataWithCredential(credential);
await user.updateEmail(email);
return email;
错误信息
reauthenticateAndRetrieveDataWithCredential 失败:第一个参数“凭据”必须是有效的凭据。
我只有宣誓认证(没有电子邮件+密码)。所以我无法弄清楚credential
火力基地需要什么。有什么帮助吗?
编辑:
出于某种原因,我的firebase.auth.OAuthCredential
或 ( firebase.auth.AuthCredential
) 返回未定义。用户已登录/验证。
解决方案
在一个 Vue.js 项目中遇到了这个问题,我们有一个firebase.js
文件来处理const
.
希望这将有助于某人在使用类似设置时节省时间。
文件: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()
changePassword()
在其他脚本文件或里面的例子*.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"
...
仅导入{ auth } from './firebase.js
然后调用auth.EmailAuthProvider()
.
如何访问在firebase.auth()上找到的其他类...
export const fb = firebase
在firebase.js
import { fb, auth } from './firebase.js'
你在哪里写你的函数需要电话
fb.auth.EmailAuthProvider.credential()
或其他课程
推荐阅读
- c++ - 如何将着色器中生成的浮点数据而不是颜色拉回 CPU?
- solidity - uint256 对于weis 的数量还不够吗?
- algorithm - ACM 问题:长字符串的不同子字符串的数量
- swift - 如何检查 RXSwift 中的 observable 是否为空?
- c# - v2 上 C# 中的 Azure 函数 - 如何访问门户应用程序设置
- sql - 求和数据并选择PK中的最大值
- android - 如何使用 Expandable 关闭 NavigationView 中的组菜单
- python - wkhtmltopdf - 由于网络错误而退出代码 1:ContentNotFoundError
- javascript - 使用 Styled-System 创建自定义样式的道具
- python-3.x - 什么 GetPostData() 使用 cefpython3 返回 { }?