Tim Lindsey Tim Lindsey - 1 month ago 5x
React JSX Question

Passing observer into redux-sagas

I'm trying to leverage a firebase observable from within the redux-sagas framework but I'm having trouble doing this without a hack. I'm trying to use firebase's "onAuthStateChange" function as shown here

firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
} else {
// No user is signed in.

essentially the observer executes whenever a user signs in or out

In my firebase utility file my method looks like this:

authChanged: () =>{
return firebaseAuth.onAuthStateChanged(callback);

then in my saga, for the moment, I'm simply trying to log to the console whenever the observer observes something:

export function* loginState(){
console.log('User logged in!')
console.log('User logged out')

This fails due to 'callback' not being defined. I'm essentially trying to curry the observer to pass to sagas but it's not working. My workaround is to pass the full firebase auth object to my login/logout saga and then create the observer in there. That works but seems like a hack. Any help would be hugely appreciated.


It seems like you meant to have callback as a parameter to authChanged but authChanged currently takes no parameters. Here's what you probably meant to do:

authChanged: (callback) => {
    return firebaseAuth.onAuthStateChanged(callback);

I'm not sure I understand what you mean by currying the observer but you could also do something like this to curry the firebase method to use as your method:

    authChanged: ::firebaseAuth.onAuthStateChanged,