簡體   English   中英

身份平台 / Firebase 錯誤(身份驗證/無效刷新令牌)

[英]Identity Platform / Firebase Error (auth/invalid-refresh-token)

我正在將現有的工作Firebase Auth 項目升級到 Identity Platform 以從租戶的善意中受益。

我目前正在針對本地模擬器對此進行測試,並面臨以下問題:

  • 我的用戶不再出現在模擬器中。 但是,我認為這種行為是預期的,因為我正在針對租戶創建用戶,而不再是默認項目用戶“池”
  • 用戶也不會出現在 GCP 控制台 然而,雲 Function 中的getUserByEmail()方法返回注冊用戶。 因此,我不知道這些用戶當前是在哪里創建的……

通過generateSignInWithEmailLink()驗證用戶工作正常。

但是,在此之后的漏斗中的幾個步驟中,當使用await user?.getIdToken(true)方法時,我收到以下錯誤: Uncaught (in promise) FirebaseError: Firebase: Error (auth/invalid-refresh-token)並且無法弄清楚為什么。

有趣的是, user.getIdTokenResult()方法工作正常並且不會產生任何錯誤。

在此處輸入圖像描述

我的整個片段:

 const getCurrentUser = async (): Promise<Auth["currentUser"]> => {
    return new Promise((resolve, reject) => {
      const unsubscribe = onAuthStateChanged(
        auth,
        async (user) => {
          if (user) {
            if (document.referrer.includes("stripe")) {
            //   console.log({ user });
            await user?.getIdToken(true);
            console.log({ after: user });
           }
            state.isAuthenticated.value = true;
            state.user.value = user;
            try {
           
              const { claims } = await user.getIdTokenResult();
             
              state.claims.value = claims;
              if (typeof claims.roles === "string") {
              
                if (claims.active && claims.roles.includes("account_owner")) {
                  state.isActive.value = true;
                }
              }
            } catch (e) {
              console.log(e);
              if (e instanceof Error) {
                throw new Error();
              }
            }
          }
          unsubscribe();
          resolve(user);
        },
        (e) => {
          if (e instanceof Error) {
            state.error.value = e.message;
            logClientError(e as Error);
          }
          reject(e);
        }
      );
    });
  };

作為參考,我正在使用 Vue 3 / Vite 存儲庫。

歡迎任何建議,

謝謝,

S.

對於任何正在尋找答案的人,這里只是一個快速跟進。 我在 firebase-tools Github 上提出了錯誤報告並且:

  • 用戶未出現在模擬器 UI 中:firebase 團隊確認的行為。 模擬器目前不支持多租戶。 然而,根據我的經驗,使用具有多租戶的模擬器,基本功能似乎有效:創建用戶、檢索用戶。 然而不可能將它們可視化或導出它們。

  • 刷新令牌錯誤:錯誤已由 firebase 團隊確認並正在分類中。 可能需要一些時間才能修復(如果有的話?)。 所以現在,即使遠非理想,我已經在我的代碼中添加了條件檢查以跳過本地主機上令牌的強制刷新。 相反,我注銷並重新登錄我希望在聲明中看到一些變化的用戶,因為這個過程不會出錯。 另一種解決方案是使用實際的 Firebase Auth 實例而不是本地模擬器,但將本地主機/模擬器資源與實際資源結合起來感覺有點混亂,即使使用開發帳戶也是如此。

GH 問題:在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM