Firebase 身份验证类型错误 : Cannot read property 'getIdToken' of null

标签 firebase ecmascript-6 firebase-authentication

我正在尝试使用

获取用户 token
import { 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/

相关文章:

java - 如何将一堆照片同步到 firebase

javascript - Firebase 云函数 : how to get data from `change` and `context` ?

javascript - 提取 URL 查询字符串 ES6

javascript - firebase多位置更新用户身份验证和数据库

java - 无法调用方法 FirebaseApp.delete()

firebase - SwiftUI 和 MVVM : How to display data from Firebase/Firestore in View?

javascript - 无法在 Node JS 应用程序中运行 Firebase

javascript - JS 按特定排序顺序排序

javascript - 当函数在构造函数中绑定(bind)时如何在 ES6 React 中向事件处理程序添加参数

javascript - Firebase Auth 在登录后自动注销用户