Handling firebase auth with react-router
I made a PrivateRoute
component and pass it an authenticated
prop which I get from the redux store in the component where I use the PrivateRoute
When I login with firebase I put user data in the redux store. So in my case i would map state to props
const mapStateToProps = (state) => ({
authenticated: !!state.user.uid,
})
And give the authenticated prop to my PrivateRoute
component
const PrivateRoute = ({ component: Component, authenticated, path, exact }) => {
return (
<Route
path={path}
exact={exact}
render={props =>
authenticated
? <Component {...props} />
: <Redirect to="/login"/>}
/>
)
}