-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthenticatedComponent.jsx
More file actions
46 lines (36 loc) · 1.11 KB
/
Copy pathAuthenticatedComponent.jsx
File metadata and controls
46 lines (36 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React from 'react';
import { connect } from 'react-redux';
//import { pushState } from 'redux-router';
import { checkAuth } from 'reduxApp/modules/auth';
export function requireAuthentication(Component) {
class AuthenticatedComponent extends React.Component {
componentWillMount() {
this.props.checkAuth();
}
// componentWillReceiveProps(nextProps) {
// this.checkAuth();
// }
// checkAuth() {
// if (!this.props.isAuthenticated) {
// let redirectAfterLogin = this.props.location.pathname
// this.props.dispatch(pushState(null, `/login?next=${redirectAfterLogin}`))
// }
// }
render() {
return (
<div>
{this.props.isAuthenticated === true
? <Component {...this.props}/>
: null
}
</div>
);
}
}
return connect(
(state) => ({
isAuthenticated: !!state.auth.user,
}),
{ checkAuth }
)(AuthenticatedComponent);
};