【问题标题】:Get currentuser from local with firebase/auth (beta 9)使用 firebase/auth (beta 9) 从本地获取当前用户
【发布时间】:2021-06-07 07:28:23
【问题描述】:

当前版本 9 中的 Firebase/auth 默认将会话存储在 indexedDB 中。但是我在加载应用程序时找不到在 firebase 中检索本地会话的方法。

onAuthStateChanged 在应该可以检索“保存的当前用户会话”时需要时间来准备身份验证。

auth.onAuthStateChanged(function (userData) {
  if (userData) {
    // User is signed in.
  } else {
    // No user is signed in.
  }
});

有没有办法直接访问本地当前用户而不需要手动访问indexedDB?而不是像gist 那样将 indexedDB 打包,或者自己将用户发送到 localStorage?

【问题讨论】:

    标签: firebase web firebase-authentication beta


    【解决方案1】:

    您可能正在寻找这个:

    import { getAuth } from "firebase/auth";
    
    const auth = getAuth();
    const user = auth.currentUser; // null if no user
    

    您可以在documentation找到更多信息

    【讨论】:

      猜你喜欢
      • 2020-08-05
      • 1970-01-01
      • 2018-01-10
      • 2020-01-01
      • 2020-08-22
      • 2018-11-21
      • 2020-11-30
      • 1970-01-01
      • 2020-03-03
      相关资源
      最近更新 更多