nuxt-community / firebase-module

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

Auth Emulator Bug verification session on refresh page with getAccountInfo #465

Closed tibs245 closed 3 years ago

tibs245 commented 3 years ago

Version

"nuxt": "^2.15.1",
"firebase": "^8.2.8",
"@nuxtjs/proxy": "^2.1.0",
"@nuxtjs/pwa": "^3.3.5",
"@nuxtjs/firebase": "^7.5.0",
"core-js": "^3.9.0",

Steps to reproduce

(In this exemple, my Auth emulator is http://localhost:9099)

What is Expected?

But fail because this session not exist on google server So I am disconnected each time the page is refreshed

What is actually happening?

The firebase must to send the request getAccountInfo for valid the session to : http://localhost:9099/www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo

I don't know if this a Nuxt Firebase module bug, a firebase bug or me with a bad configuration. If it's firebase bug, I am sorry for this issue.

But for resolve this bug temporary I have edit the firebase auth service worker and it's work.

I edit : static/firebase-auth-sw.js

  if (!expectsHTML || !isSameOrigin || !isHttps || isIgnored) {
+    if (event.request.url.startsWith('https://www.googleapis.com/identitytoolkit/')) {
+     event.respondWith(
+        fetch({
+          ...event.request,
+          ...{ url: event.request.url.replace(/https:\/\//, 'http://localhost:9099/') },
+        })
+      )
+    } else event.respondWith(fetch(event.request))
-    event.respondWith(fetch(event.request))
    return
  }

But I think It's not the better way for resolve it

lupas commented 3 years ago

Hmm that's interesting, I am running in the same issue, but not constantly. Even your workaround does not seem to work all the time for me...

I think we should be able to fix this directly in the module and also add the FIREBASE_AUTH_EMULATOR_HOST env variable if emulators are activated, without you having to do it manually.

I'll need to have a closer look at this sometime but won't have time this weekend - Let me know if you find out more!

tibs245 commented 3 years ago

For my side, This problem is constantly and my solution work. I have test 2 days for see if I have the same problem of you but I don't have.

If you have more information when my solution do not work for you and may be how I can reproduce it. I can search a global solution

johngtb commented 3 years ago

Hmm that's interesting, I am running in the same issue, but not constantly. Even your workaround does not seem to work all the time for me...

I think we should be able to fix this directly in the module and also add the FIREBASE_AUTH_EMULATOR_HOST env variable if emulators are activated, without you having to do it manually.

I'll need to have a closer look at this sometime but won't have time this weekend - Let me know if you find out more!

Any updates on this yet?

fellnerse commented 3 years ago

I have the same issue...can not use the emulator at all with this bug the fix does not work for me, the file is regenerated when restarted

rgilsimoes commented 3 years ago

I'm also having the same issue: "nuxt": "^2.15.3", "@nuxtjs/firebase": "^7.4.1", dev: "firebase-admin": "^9.5.0",

nuxt.config.js

workbox: { importScripts: [ // ... "/firebase-auth-sw.js" ], // by default the workbox module will not install the service worker in dev environment to avoid conflicts with HMR // only set this true for testing and remember to always clear your browser cache in development dev: process.env.NODE_ENV === "development" }

auth: { persistence: true, initialize: { onAuthStateChangedAction: "onAuthStateChanged" }, ssr: true, emulatorPort: process.env.NODE_ENV === "development" ? 9099 : undefined, disableEmulatorWarnings: true },

tibs245 commented 3 years ago

I have do pull request for definitively fix this problem. But I think always isn't better solution for long term.

If you have kid problem : FirebaseAuthError: Firebase ID token has no "kid" claim. kid problem

Don't forget to set FIREBASE_AUTH_EMULATOR_HOST

For linux : export FIREBASE_AUTH_EMULATOR_HOST="localhost:9099" && npm run dev

For use this fix before pull merged : edit directly node_modules/@nuxtjs/firebase/lib/sw-templates/firebase-auth-sw.js template file with my first solution edition.

Is not clean but this work and nuxt not rewrite it

lupas commented 3 years ago

Published with v7.6.1