Added admin check to admin page

This commit is contained in:
Jeremi Nieminen
2018-12-09 22:00:51 +02:00
parent a56d7787be
commit 48b7a6e9ca
2 changed files with 21 additions and 1 deletions
+2 -1
View File
@@ -75,7 +75,8 @@ class App extends Component {
<Switch>
<Route path={process.env.PUBLIC_URL + '/login'} render={() => (
this.props.user ?
<Redirect to={process.env.PUBLIC_URL + '/register'} /> :
(this.props.user.admin? <Redirect to={process.env.PUBLIC_URL + '/administration'} /> : <Redirect to={process.env.PUBLIC_URL + '/register'} />)
:
<LoginPage />
)} />
<Route exact path={process.env.PUBLIC_URL + '/'} render={() => <Redirect to={process.env.PUBLIC_URL + '/login'} />} />
+19
View File
@@ -3,6 +3,25 @@ import { connect } from 'react-redux'
import './TopicFormPage.css'
class AdminPage extends React.Component {
componentWillMount() {
try {
if (window.localStorage.getItem('loggedInUser') === null) {
window.location.replace(process.env.PUBLIC_URL + '/')
} else {
const token = JSON.parse(window.localStorage.getItem('loggedInUser'))
if (!token.user.admin || token === undefined || token === null) {
window.location.replace(process.env.PUBLIC_URL + '/')
}
}
} catch (e) {
console.log('error happened', e.response)
this.props.setError('Some error happened')
setTimeout(() => {
this.props.clearNotifications()
}, 3000)
}
}
render() {
return (
<div className="admin-page-container">