'Firebase onAuthStateChanged listener never fires on localhost despite being authorized
Fairly experienced with Firebase, encountering a strange and unintuitive bug. I've written a Firebase authentication wrapper using the React Context API, and track the currently logged in user with a listener. Here is my code:
useEffect(() => {
console.log("Registering firebase auth listener");
const unsubscribe = fa.onAuthStateChanged(
fa.getAuth(),
function (user) {
console.log(user);
setCurrentUser(user);
},
(error) => console.error(error),
() => console.warn("Firebase listener unhooked")
);
return unsubscribe;
}, []);
Up until recently, this worked fine, but something has caused it to stop working only on localhost with no error message. The print at the top for checking that the hook runs gets logged, but nothing else.
I don't understand what's going on here. Is there something obvious I've missed?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

