MCPcopy Index your code
hub / github.com/reactGo/reactGo / requireAuthentication

Function requireAuthentication

app/components/authenticateComponent.jsx:5–40  ·  view source on GitHub ↗
(Component)

Source from the content-addressed store, hash-verified

3import { updatePath } from 'redux-simple-router';
4
5export function requireAuthentication(Component) {
6 class AuthenticateComponent extends React.Component {
7
8 constructor(props) {
9 super(props);
10 }
11
12 componentWillMount() {
13 const { isAuthenticated, dispatch } = this.props;
14 if (!isAuthenticated) {
15 dispatch(updatePath(`/login?next=${this.props.location.pathname}`));
16 }
17 }
18
19 render() {
20 return (
21 <Component {...this.props} />
22 );
23 }
24 }
25
26 AuthenticateComponent.propTypes = {
27 dispatch: PropTypes.func.isRequired,
28 isAuthenticated: PropTypes.bool,
29 location: PropTypes.object
30 };
31
32 function mapStateToProps(state) {
33 return {
34 token: state.user.token,
35 isAuthenticated: state.user.authenticated
36 };
37 }
38
39 return connect(mapStateToProps)(AuthenticateComponent);
40};

Callers 1

routes.jsxFile · 0.90

Calls 1

connectFunction · 0.85

Tested by

no test coverage detected