React Redux Firebase + Firestore - cannot read userProfile collection with data after migration

338 views Asked by At

Currently I've been moving my firebase app from real time database to the cloud firestore. For that purpose I have two separate firebase projects:

  • my-project <- current project my app uses
  • my-project-firestore <- project I want to migrate to

I exported all the users from the current project and imported them back to the new one.

Currently my react-redux-firebase config looks like that

export const reduxFirebase = {
    userProfile: "users"
};

it makes the user profiles are being saved to the real time database under path /users Now I moved all of the documents under this path to the same path in the cloud firestore database by using such python script

def migrate_users(project_id, firebase_app, firestore_client):
    path = "/users"
    firestore_path = "users/{customer_id}"
    print(
        f"migrating from project: {project_id}, partner_id: {partner_id}, path: {path}"
    )
    ref = db.reference(path, firebase_app)
    document = ref.get() or {}
    items = document.items()
    size = len(items)
    for counter, item in enumerate(items):
        customer_id = item[0]
        notes = item[1]
        print(f"{counter+1}/{size} -- migrating customer_id: {customer_id}")
        current_document = firestore_client.document(
            firestore_path.format(
                customer_id=customer_id
            )
        )
        current_document.set(notes)

So now in theory I should have the same state of data regarding users and their profiles in both databases.

I added the redux-firestore dependency

    "react-redux-firebase": "2.5.1",
    "redux-firestore": "^0.13.0",

I changed some code in my react app

   export const reduxFirebase = {
       userProfile: "users",
       useFirestoreForProfile: true
   };
...
   firebase.initializeApp(firebaseConfig());
   firebase.firestore()
...
  const composedEnhancers = composeEnhancers(
        reactReduxFirebase(firebase, reduxConfig),
        reduxFirestore(firebase),
        applyMiddleware(...middleware),
        ...enhancers
    );

After I login into my app using my gmail account, which in firebase has some id let's say qWertYzAbcdEfhJijk, when I try to fetch all documents from the firestore under the path /users I can only fetch documents which were created when somebody logged into my app with new config. It doesn't see all the user data I migrated

    export default compose(
        withStyles(styles),
        firestoreConnect(props => [
            {
                collection: "users",
                storeAs: "users"
            },
        ]),
        connect(mapStateToProps, mapDispatchToProps)
    )(ActiveUsersPanel);
...
const mapStateToProps = (state, props) => {
    return {
        users: state.firestore.data.users
    };
};
...
function ActiveUsersPanel(props) {
    const {firebase, classes, users} = props;
    console.log(users);
...

the result contains only one item

{"qWertYzAbcdEfhJijk":{"id":"qWertYzAbcdEfhJijk","avatarUrl":"https://lh6.go...","displayName":"My name","email":"[email protected]","providerData":[{"email":"[email protected]","phoneNumber":null,"photoURL":"https://lh6.googl...","providerId":"google.com","uid":"115418232581098xxxxxx"}]}}

And doesn't contain all of the documents I migrated from the old database even though they look the same

Why is it happening and how to solve it ?

EDIT: maybe this picture can help to better understand what my issue is

enter image description here

EDIT: I noticed that when I change the react-redux-firebase config to point to other path

export const reduxFirebase = {
           userProfile: "storeUsers",
           useFirestoreForProfile: true
       };

suddenly it's able to read the /users correctly in my component

0

There are 0 answers