prescottprue / react-redux-firebase

Redux bindings for Firebase. Includes React Hooks and Higher Order Components.
https://react-redux-firebase.com
MIT License
2.55k stars 556 forks source link

bug(reducer): auth is empty when using login, but not empty when using createUser #388

Open mnindrazaka opened 6 years ago

mnindrazaka commented 6 years ago

when i tried to use auth with login() and try to shows auth props, i got this login

but when i use createUser() i got this auth props createUser

this is my login() code image

this is my createUser() code image

and this is how i attach auth props to a component image

i use react native and react-native-firebase

yossi-shasho commented 6 years ago

+1 happens to me too, using React web

ytwater commented 6 years ago

I'm seeing the same thing.

this.props.firebase.login always seems to be triggering @@reactReduxFirebase/LOGIN_ERROR

For me, I was able to use the standard firebase login and react-redux-firebase still caught the auth change and updated the auth and profile state.

Standard Login

firebase
  .auth()
  .signInWithEmailAndPassword(email, password)
  .then(user => console.log(user));

Credential Login

const credential = firebase.auth.EmailAuthProvider.credential(
  email,
  password
);
firebase
  .auth()
  .signInWithCredential(credential)
  .then(user => console.log(user));
prescottprue commented 6 years ago

@ytwater LOGIN_ERROR is dispatched with null to reset error state when logging in.

I'm look into this.

krzysu commented 6 years ago

I had the same issue, the problem was the order of functions in redux compose, see example below:

// doesn't work, react-redux-firebase actions are not dispatched
const store = createStore(
  rootReducer,
  compose(
    composeWithDevTools(),
    reactReduxFirebase(firebase, config),
    reduxFirestore(firebase),
    applyMiddleware(thunk.withExtraArgument(getFirebase))
  )
);
// works
const store = createStore(
  rootReducer,
  compose(
    applyMiddleware(thunk.withExtraArgument(getFirebase)),
    reactReduxFirebase(firebase, config),
    reduxFirestore(firebase),
    composeWithDevTools()
  )
);

I hope it helps! :)

prescottprue commented 6 years ago

@krzysu Great to know that solves it, thanks for reaching out. Seems like it is caused by the same thing causing #400.

GioLogist commented 6 years ago

Running into this error on a project of ours currently, tried switching the order of compose and that didn't seem to do the trick either.

prescottprue commented 6 years ago

@GioLogist Which version are you using? Did you try installing from the @next tag?

GioLogist commented 6 years ago

@prescottprue Sorry for the delay - actually fixed it immediately after and forgot to update!

Was my foolish mistake. Forgot to initialize firebase before setting up the store 😝 (was a long day, i swear!)

gotdibbs commented 5 years ago

I'm having the same issue with on v3. It appears as though authActions.init never gets invoked so there is no listener setup for successful logins. I'm not sure where the functionality from enhancer.js is intended to map to in the new version, but that operation and createAuthIsReady seem to be missing currently.

prescottprue commented 5 years ago

@gotdibbs Thanks for the detailed reporting - I'm going to look into calling that as part of the provider for v3

prescottprue commented 5 years ago

@gotdibbs v3.0.0-alpha.4 now includes auth initialization in the Providers, but I don't believe that addresses this issue, so going to leave it open.