mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
47 lines
944 B
JavaScript
47 lines
944 B
JavaScript
import React, { Component } from "react";
|
|
import PropTypes from "prop-types";
|
|
import { connect } from "react-redux";
|
|
import { push } from "react-router-redux";
|
|
|
|
import paths from "../../router/paths";
|
|
import userInterface from "../../interfaces/user";
|
|
|
|
export class AuthenticatedAdminRoutes extends Component {
|
|
static propTypes = {
|
|
children: PropTypes.node,
|
|
dispatch: PropTypes.func,
|
|
user: userInterface,
|
|
};
|
|
|
|
componentWillMount() {
|
|
const {
|
|
dispatch,
|
|
user: { global_role },
|
|
} = this.props;
|
|
const { HOME } = paths;
|
|
|
|
if (global_role !== "admin") {
|
|
dispatch(push(HOME));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
render() {
|
|
const { children, user } = this.props;
|
|
|
|
if (!user) {
|
|
return false;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = (state) => {
|
|
const { user } = state.auth;
|
|
|
|
return { user };
|
|
};
|
|
|
|
export default connect(mapStateToProps)(AuthenticatedAdminRoutes);
|