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 559 forks source link

profile custom claims not updated after registration #1150

Open capi1O opened 2 years ago

capi1O commented 2 years ago

I am using RRF v3.11.0, to verify if a user is logged in I do the following:

import { isLoaded, isEmpty } from 'react-redux-firebase';
import { useSelector } from 'react-redux';

const { auth, profile } = useSelector((state) => state.firebase);
const loaded = isLoaded(auth) && isLoaded(profile);
const loggedIn = loaded && !isEmpty(auth) && (profile?.token?.claims?.role === USER_ROLE);

the role is set by a firestore function onUserCreate which is called as you would have guess at sign up.

The value of the custom claim role "read" by my useSelector is however not updated, it is still undefined no matter how long I wait, whereas it is correctly set on "server" (on firestore).

The app needs to be reloaded and then the role value is as expected. Here is my RRF config:

const reactReduxFirebaseConfig = {
    userProfile: 'users',
    useFirestoreForProfile: true,
    attachAuthIsReady: true,
    updateProfileOnLogin: true,
    enableClaims: true,
};

If you wonder why I check this role before to grant the user access to my app, well, I have my reasons.