Setting up authentication with reactjs, firebase (google auth), react-router and redux.
The problem is very simple but I can't find any resource online or answers to fix it.
Unable to read roperty of uid (user id with firebase) because it's telling me it's undefined? I've set this up that Private routes is a new component and it's been imported in my app router. I also plan to have a public routes as well.
Here is my code along with screenshots of error.
PrivateRoute.js
import React from 'react';
import { connect } from 'react-redux';
import { Route, Redirect } from 'react-router-dom';
export const PrivateRoute = (props) => (
<Route {...props} />
);
const mapStateToProps = (state) => ({
isAuthenticated: !!state.auth.uid <-error on this uid
});
export default connect(mapStateToProps)(PrivateRoute);
AppRouter.js
import PrivateRoute from './PrivateRoute'
<Route path="/" component={Login} exact={true}/>
<PrivateRoute path="/dashboard" component={Dashboard} />
<PrivateRoute path="/create" component={AddExp}/>
Screenshot of error when I'm logged out and try accessing /create private route
Updated to add redux store configure file
import authenticationReducer from '../reducers/authentication'
export default () => {
const store = createStore(
combineReducers({
expenses: expensesReducer,
authentication: authenticationReducer
}),
composeEnhancers(applyMiddleware(thunk))
);
return store;
};
Auth reducer (just incase it's needed)
export default (state = {}, action) => {
switch (action.type) {
case 'LOGIN':
return {
uid: action.uid
};
case 'LOGOUT':
return {
};
default:
return state;
}
};

authin your store