When a user logs in to the app, their information (username, email, etc) is saved in redux. I am able to log in, but my issue is accessing the actual information after logging in.
Here is the code where I am trying to access redux:
const mapStateToProps = state => ({
user: state.user,
});
class LikeComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
likerUID: Firebase.auth().currentUser.uid,
likerUsername: this.props.user.username, //<------------------ Issue is here
Error:
TypeError: undefined is not an object (evaluating '_this.props.user.username')
How I save the information to redux when a user is authenticated:
dispatch(authUser(Firebase.auth().currentUser.uid, Firebase.auth().currentUser.email, doc.data().username));
Finally my redux actions:
export const authUser = (userid, userEmail, username) => (dispatch) => {
const data = {
id: userid,
username,
email: userEmail,
};
dispatch(setAuthUser(data));
};
In my redux "authUser", I added the line console.log(username); which properly logs the username:
export const authUser = (userid, userEmail, username) => (dispatch) => {
const data = {
id: userid,
username,
email: userEmail,
};
console.log(username);
dispatch(setAuthUser(data));
};
So the issue is with accessing it, not setting it.