React-redux-firebase: feat(auth): Reload auth

Created on 16 Sep 2017  路  8Comments  路  Source: prescottprue/react-redux-firebase

Calling firebase.auth().currentUser.reload() fetches latest account data from firebase. An example use case for this is when we want to check if user has verified their email.

This however does not update the Redux state. My workaround is pretty simple but ugly. I'm dispatching a LOGIN action with the new reloaded auth object.

async function reloadAuth() {
    if (!firebase.auth().currentUser) return;

    await firebase.auth().currentUser.reload();
    const auth = firebase.auth().currentUser;

    store.dispatch({ type: '@@reactReduxFirebase/LOGIN', auth });
}

A better solution would be a reloadAuth function on firebaseInstance and a dedicated RELOAD_AUTH action type.

I would be glad to submit a pull request if you think this would be a good addition.

Most helpful comment

All 8 comments

@lench4991 Yes, I think this would be a great addition. Feel free to open a pull request.

@lench4991 This can be added to v1.5, but it should also be added to v2.

Into v2.0.0-beta.9 with matching tests. Will wait to close until it is published.

Shouldn't this reloadAuth be updating the firebase auth state? I see the message but the state is not being updated.

@lopesmcc Yes it should. The tests should be confirming this too, so I will attempt to replicate.

If I am able to replicate, we will reopen this to track.

Thanks for reporting!

Hi again @prescottprue.
Has this been fixed? I think not by looking at the current reducers logic.
If you want I can prepare a PR with it.

@lopesmcc Here is the source of the reloadAuth function that dispatches the AUTH_RELOAD_SUCCESS action.

It looks like you are right about there is not a reducer case for it (great catch), so it would be awesome if you wanted to open a PR! Don't worry too much about updating the tests if you don't have time (can be handled later).

Was this page helpful?
0 / 5 - 0 ratings