You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a web app where auth is handled in a web worker. I use Comlink to call methods in the worker from the main thread.
I use firebase-auth-ui 6.0.0 for the (you guessed it) auth ui.
Find the relevant example code below. (note: I've extracted and simplified the code so there may be a typo/etc in there)
Before I switched to Firebase 9 (compat), this worked fine.
After uprading from 8.10 to 9.6, the onAuthStateChanged callback is called once with the user object = null. Since I was already logged in before (prior to upgrading to 9.6), I expect the callback to be called with a User object.
At this point my app loads the auth-ui and displays it. When I try to (re)log in using auth-ui, the callback is never called with the user object. From what I can tell, the auth-ui library does successfully log me in, but nothing happens in my web app.
Reloading the web app doesn't help either. I also tried clearing the application data (Dev tools > Application > Storage > Clear site data (with every option checked)).
Relevant Code:
/* Web worker */import*asComlinkfrom'comlink';importfirebasefrom'firebase/compat/app';import'firebase/compat/auth';constfirebaseApp=firebase.initializeApp({/* ... */);constfirebaseAuth=firebaseApp.auth();functionauth(callback){firebaseAuth.onAuthStateChanged((user)=>{console.log('onAuthStateChanged:',(user!==null));// this always logs `false` once, and only onceif(cb){cb(user);}},(error)=>{console.log('onAuthStateChanged error:',error);}););Comlink.expose({
auth
});/* Browser */// Set up worker and wrap in Comlinkworker=newWorker(/* ... */);workerApi=Comlink.wrap(worker);// Callback as Comlink.proxyconstcb=Comlink.proxy(user=>{console.log('auth():',user);});// Call authworkerApi.auth(cb);
The text was updated successfully, but these errors were encountered:
Possibly related: #5370 - except it explicitly mentions that firebase.auth().onAuthStateChanged does work when using the compat version:
In a classic worker, however, it is still possible to use firebase when importing the library from CDN in a non-modular way:
Update, some additional info:
I've tried a couple of older versions (9.5, 9.4.1, 9.2.0, 9.0.2 and 9.0.0) and none of these versions worked as I expect. auth().onAuthStateChanged() is called only once, and always with User = null.
I also tested if the auth().onAuthStateChanged() callback was called correctly in the main thread (browser) by loading the compat auth there and doing the necessary set up - and it does. In the worker, however, still nothing happens.
I noticed that the fetches for getAccountInfo are not executed for the worker, only for the main thread. As soon as I roll back to 8.10.0, I see the request happening for the worker:
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Steps to reproduce:
I have a web app where auth is handled in a web worker. I use Comlink to call methods in the worker from the main thread.
I use firebase-auth-ui 6.0.0 for the (you guessed it) auth ui.
Find the relevant example code below. (note: I've extracted and simplified the code so there may be a typo/etc in there)
Before I switched to Firebase 9 (compat), this worked fine.
After uprading from 8.10 to 9.6, the
onAuthStateChanged
callback is called once with the user object = null. Since I was already logged in before (prior to upgrading to 9.6), I expect the callback to be called with a User object.At this point my app loads the auth-ui and displays it. When I try to (re)log in using auth-ui, the callback is never called with the user object. From what I can tell, the auth-ui library does successfully log me in, but nothing happens in my web app.
Reloading the web app doesn't help either. I also tried clearing the application data (Dev tools > Application > Storage > Clear site data (with every option checked)).
Relevant Code:
The text was updated successfully, but these errors were encountered: