Fix bug in protected routing

This commit is contained in:
John Lyon-Smith
2018-03-02 14:52:18 -08:00
parent d347adcf33
commit 7756963eb2
3 changed files with 43 additions and 33 deletions

View File

@@ -12,6 +12,10 @@ export class ProtectedRoute extends React.Component {
}),
}
static defaultProps = {
roles: ['administrator']
}
constructor(props) {
super(props)
this.updateComponent = this.updateComponent.bind(this)
@@ -34,17 +38,17 @@ export class ProtectedRoute extends React.Component {
if (user) {
if (user.pending) {
// The Api might be in the middle of fetching the user information
// The API might be in the middle of fetching the user information
// Return something and wait for login evint to fire to re-render
return <div />
}
let roles = this.props.roles
if (!roles || roles.includes(user.role)) {
if (roles && roles.includes(user.role)) {
return <Route {...this.props} />
} else if (!!user.role && user.role === 'broker') {
return <Redirect to='/broker-dashboard' />
} else if (!!user.role && (user.role === 'employee' || 'administrator' || 'executive')) {
return <Redirect to='/dashboard' />
} else {
return <Redirect to='/' />
}
} else {
return <Redirect to={`/login?redirect=${this.props.location.pathname}${this.props.location.search}`} />