Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tibs245 opened this issue Feb 20, 2021 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@tibs245
Copy link
Contributor

tibs245 commented Feb 20, 2021

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

  • Use Firestore auth with emulator
  • Connect user
  • Refresh the page (F5 or CTRL + R)

(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
Copy link
Member

lupas commented Feb 20, 2021

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!

@lupas lupas added the bug Something isn't working label Feb 20, 2021
@lupas lupas pinned this issue Feb 20, 2021
@tibs245
Copy link
Contributor Author

tibs245 commented Feb 23, 2021

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
Copy link

johngtb commented Mar 19, 2021

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
Copy link

fellnerse commented Apr 6, 2021

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
Copy link

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
Copy link
Contributor Author

tibs245 commented Apr 9, 2021

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
Copy link
Member

lupas commented Jun 11, 2021

Published with v7.6.1

@lupas lupas closed this as completed Jun 11, 2021
@lupas lupas unpinned this issue Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants