我正在尝试使用
获取用户 tokenimport { auth, database } from "firebase";
await token = await auth().currentUser.getIdToken();
但是,我收到了这个错误,
TypeError: Cannot read property 'getIdToken' of null
它有时有效,但有时无效。我在这里做错了什么?
最佳答案
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
user.getIdToken().then(function(data) {
console.log(data)
});
}
});
关于Firebase 身份验证类型错误 : Cannot read property 'getIdToken' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46636907/