Fix admin/user login issues
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import React from 'react'
|
||||
import { Route, Redirect } from 'react-router'
|
||||
import { PropTypes } from 'prop-types'
|
||||
import { api } from 'src/API'
|
||||
import autobind from 'autobind-decorator'
|
||||
import React from "react"
|
||||
import { Route, Redirect } from "react-router"
|
||||
import { PropTypes } from "prop-types"
|
||||
import { api } from "src/API"
|
||||
|
||||
export class ProtectedRoute extends React.Component {
|
||||
static propTypes = {
|
||||
@@ -13,33 +12,32 @@ export class ProtectedRoute extends React.Component {
|
||||
admin: PropTypes.bool,
|
||||
}
|
||||
|
||||
@autobind
|
||||
updateComponent() {
|
||||
this.forceUpdate()
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.addListener("login", this.updateComponent)
|
||||
api.addListener("logout", this.updateComponent)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
api.removeListener("login", this.updateComponent)
|
||||
api.removeListener("logout", this.updateComponent)
|
||||
}
|
||||
|
||||
render(props) {
|
||||
const user = api.loggedInUser
|
||||
|
||||
if (user.pending) {
|
||||
return null
|
||||
// If login token has not yet been confirmed, park until it is and redirect back here
|
||||
return (
|
||||
<Route
|
||||
render={() => (
|
||||
<Redirect
|
||||
to={`/parking?redirect=${this.props.location.pathname}`}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
} else {
|
||||
// If we are not a user or an admin go to the login page
|
||||
if (!user._id || (this.props.admin && !user.administrator)) {
|
||||
return (
|
||||
<Redirect
|
||||
to={`/login?redirect=${this.props.location.pathname}${
|
||||
this.props.location.search
|
||||
}`}
|
||||
<Route
|
||||
render={() => (
|
||||
<Redirect
|
||||
to={`/login?redirect=${this.props.location.pathname}${
|
||||
this.props.location.search
|
||||
}`}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user