SSR Firebase身份验证和NuxtJS抛出身份验证FirebaseAuthError

时间:2020-05-27 17:57:54

标签: firebase authentication firebase-authentication server-side-rendering nuxtjs

我收到以下错误:

    FirebaseAuthError: Firebase ID token has incorrect "aud" (audience) claim. Expected "a" but got "b". Make sure the ID token comes from the same Firebase project as the service account used to authenticate this SDK. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.
    at FirebaseAuthError.FirebaseError [as constructor] (/Users/bla/node_modules/firebase-admin/lib/utils/error.js:42:28)
    at FirebaseAuthError.PrefixedFirebaseError [as constructor] (/Users/bla/node_modules/firebase-admin/lib/utils/error.js:88:28)
    at new FirebaseAuthError (/Users/bla/node_modules/firebase-admin/lib/utils/error.js:147:16)
    at FirebaseTokenVerifier.verifyJWTWithProjectId (/Users/bla/node_modules/firebase-admin/lib/auth/token-verifier.js:166:35)
    at /Users/bla/node_modules/firebase-admin/lib/auth/token-verifier.js:102:26 {
  errorInfo: {
    code: 'auth/argument-error',
    message: 'Firebase ID token has incorrect "aud" (audience) claim. Expected "a but got "b". Make sure the ID token comes from the same Firebase project as the service account used to authenticate this SDK. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.'
  },
  codePrefix: 'auth'
}

但是,该错误仅出现在服务器端。在客户端登录时,“ aud”似乎显示正确的值: enter image description here

代码遵循nuxtJs(https://firebase.nuxtjs.org/guide/options/#auth)中的示例:

async nuxtServerInit ({ dispatch }, { res }) {
    console.log('from Init', res.locals, res.locals.user)
    if (res && res.locals && res.locals.user) {
      const { allClaims: claims, ...authUser } = res.locals.user
      console.info(
        'Auth User verified on server-side. User: ',
        authUser,
        'Claims:',
        claims
      )

      await dispatch('onAuthStateChanged', {
        authUser,
        claims
      })
    }

那我在哪里更改服务器端的受众群体主张?

0 个答案:

没有答案