firebase / friendlyeats-web

Apache License 2.0
437 stars 393 forks source link

Auth service worker doesn't store firebaseConfig options between restarts #295

Open rlw87 opened 1 month ago

rlw87 commented 1 month ago

Description If the auth service worker is restarted, it loses the firebaseConfig options that it was given at registration time and throws an exception.

Reproduction Steps

  1. Open the web page for the first time. You'll see the log "Service worker installed with Firebase config" in the console
  2. Open developer tools, and under the Applications > Service workers tab, within auth-service-worker.js click "Stop"
  3. Refresh the page

Expected The service worker starts up again and the website loads as normal

Actual You see the following error in the console and the page doesn't load

FirebaseError: Firebase: Need to provide options, when not being deployed to hosting via source. (app/no-options).

I'm new to working with service workers so I might be missing something, but it looks to me as though the service worker should be storing the firebaseConfig somewhere other than in memory, so it can be reloaded on restart of the service worker. It looks like due to the firebaseConfig variable only being populated on 'install' event, it will never get the required configuration again unless you either manually unregister it and let it re-install, or it is updated to a newer version.

https://github.com/firebase/friendlyeats-web/blob/41b0a4dbfca6c106d926fd5e65db53577f99ea75/nextjs-end/auth-service-worker.js#L6C5-L6C19

ESRuth commented 1 month ago

I used the Development Tool to "Update on reload" which fixed the refresh issue, but that isn't a setting I can have my users change.

ysaied631 commented 4 weeks ago

Any luck with solving this?

Shahzad6077 commented 3 weeks ago

Hey @ESRuth, would you able to resolve this issue? Thanks

rlw87 commented 3 weeks ago

I've just included the firebase config in the service worker itself, rather than having the app pass it the config when it's installed. None of the values should change so I don't see why it should be a problem.

fsiatama commented 2 weeks ago

I am experiencing problems with the service worker, which fails upon page reload, sometimes after a few hours, or when the page is opened in a new browser tab.

timoteioros commented 1 week ago

Having the same problem. Didn't clone the friendlyeats project, I copy pasted the auth code into my Next.js proiect and I have the same issue with the service worker. Still searching for a permanent solution.

rashid4lyf commented 2 days ago

Having the same issue here as well. Hardcoding the values stops it from crashing however, obviously this is not ideal.