nuxt-community / firebase-module

🔥 Easily integrate Firebase into your Nuxt project. 🔥
https://firebase.nuxtjs.org
MIT License
640 stars 99 forks source link

nuxtServerInit's ctx.res.locals is always empty no matter what #600

Closed calebebteixeira closed 2 years ago

calebebteixeira commented 2 years ago

I just cloned https://github.com/lupas/nuxt-firebase-demo to make sure I got the latest version available... But ctx.res.locals is always empty:

Screenshot_2021-11-14-10-24-43_1920x1080

Version

OS: Arch Linux NODE: v14.18.1 @nuxtjs/firebase: ^8.0.0-beta.0 firebase: ^9.1.3 nuxt: ^2.15.8

Reproduction Link

https://github.com/lupas/nuxt-firebase-demo

Steps to reproduce

I just cloned this repo and launched.. that's all I did...

What is Expected?

I'm expecting ctx.res.locals not to be always empty object.

  async nuxtServerInit({ dispatch }, ctx) {
    /** Get the VERIFIED authUser on the server */

    // THIS SHOULD NOT BE EMPTY OBJECT
    console.log(ctx.res.locals)

    if (ctx.res && ctx.res.locals && ctx.res.locals.user) {
      const { allClaims: claims, ...authUser } = ctx.res.locals.user
      console.info(
        'Auth User verified on server-side. User: ',
        authUser,
        'Claims:',
        claims
      )
      await dispatch('onAuthStateChanged', {
        authUser,
        claims,
      })
    }
  },
bitpunk commented 2 years ago

I can confirm that error. Downgrading to firebase@8.10.0 and @nuxtjs/firebase@7.6.1 seems to fix that error.

Additional Versions: • node 14.18.1 • @nuxtjs/pwa 3.3.5 • firebase-admin 10.0.0

Needs some further investigation.

baradatbiu commented 2 years ago

I can confirm that error. Downgrading to firebase@8.10.0 and @nuxtjs/firebase@7.6.1 seems to fix that error.

Additional Versions: • node 14.18.1 • @nuxtjs/pwa 3.3.5 • firebase-admin 10.0.0

Needs some further investigation.

I was also helped by changing the version of the packages, but there is a problem with an empty object after a hard page reload(Ctrl + F5). @bitpunk Do you have such a problem?

bitpunk commented 2 years ago

I was also helped by changing the version of the packages, but there is a problem with an empty object after a hard page reload(Ctrl + F5). @bitpunk Do you have such a problem?

That's the expected behaviour. CTRL+F5 clears the cache (…and the service worker who retrieves the data for you) therefore the data is not available. But this should not be a problem, because users usually do not clear the cache every time. 😅

calebebteixeira commented 2 years ago

Oh man! After days trying to fix this issue... Found out that I was setting up PWA WORKBOX the wrong way:

pwa: { workbox: { importScripts: [ '/firebase-auth-sw.js' ], dev: false, // THIS NEEDs TO BE INSIDE workbox{} } // dev: false <---- I WAS ADDING "dev" HERE, THIS WAS WRONG!!!! }

Thanks everybody for all the help!