Fix bug in protected routing
This commit is contained in:
@@ -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}`} />
|
||||
|
||||
Reference in New Issue
Block a user