Closed Geczy closed 7 years ago
Solved myself using
<Route path="/" component={RequireAuthentication(HomePage)} exact />
import React from 'react'
import { connect } from 'react-redux'
import { fromAuth } from 'store/selectors'
export default function RequireAuthentication(Component) {
class AuthenticatedComponent extends React.Component {
componentWillMount() {
this.checkAuth()
}
componentWillReceiveProps(nextProps) {
this.checkAuth()
}
checkAuth() {
if (!this.props.isAuthenticated) {
this.props.history.push('/login')
}
}
render() {
return (
<div>
{this.props.isAuthenticated === true
? <Component {...this.props} />
: null
}
</div>
)
}
}
const mapStateToProps = (state) => ({
isAuthenticated: fromAuth.getIdToken(state) !== null,
})
return connect(mapStateToProps)(AuthenticatedComponent)
}
Can you please post an example of a protected route using redux social login in arc.js?