I was trying to setup react-redux-firebase in my project with user profiles as described in the docs. I ran into the following problem - everytime I created a user, the database would save the user data under "undefined":
I assume it's supposed to save the users under their uid, so for some reason the uid is undefined when the user is stored in the database. I created a sandbox that reproduces the problem: https://codesandbox.io/s/6jl07r6v7w (paste your own firebase config into store.js to try it out for yourself).
Here's how I set up the store:
import { combineReducers, createStore, compose } from "redux";
import { reactReduxFirebase, firebaseReducer } from "react-redux-firebase";
import firebase from "firebase";
export const initStore = () => {
const firebaseConfig = {
// config
};
firebase.initializeApp(firebaseConfig);
const rrfConfig = {
userProfile: "users"
};
const createStoreWithFirebase = compose(
reactReduxFirebase(firebase, rrfConfig)
)(createStore);
const rootReducer = combineReducers({
firebase: firebaseReducer
});
return createStoreWithFirebase(rootReducer);
};
and here's where I create the user:
import React, { Component } from "react";
import { withFirebase } from "react-redux-firebase";
class CreateUser extends Component {
constructor(props) {
super(props);
this.submit = this.submit.bind(this);
}
submit() {
this.props.firebase
.createUser({
email: "[email protected]",
password: "123456"
})
.then(userData => console.log(userData))
.catch(err => window.alert(err.message));
}
render() {
return <button onClick={this.submit}>create a user</button>;
}
}
export default withFirebase(CreateUser);
Looks just like in the docs to me. Anyone see the problem?
Are you using 5.*.*
of the Firebase JS SDK?
If so, this may be due to some breaking changes in the recent Firebase JS SDK release, which impacted some of of react-redux-firebase
handles profiles (believe this recently reported issue is the same).
Currently working on a fix for this, but as always open to PRs if you get a chance.
Disclosure: I am a main author of react-redux-firebase