mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
add redirect to auth_component
This commit is contained in:
parent
6877f2c8a7
commit
0c6538df2f
@ -1,12 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
import React from 'react';
|
||||
import { History } from 'react-router';
|
||||
|
||||
import UserStore from '../../stores/user_store';
|
||||
import UserActions from '../../actions/user_actions';
|
||||
|
||||
|
||||
export function AuthComponent(Component) {
|
||||
return React.createClass({
|
||||
mixins: [History],
|
||||
|
||||
getInitialState() {
|
||||
return UserStore.getState();
|
||||
},
|
||||
@ -16,6 +20,12 @@ export function AuthComponent(Component) {
|
||||
UserActions.fetchCurrentUser();
|
||||
},
|
||||
|
||||
componentDidUpdate() {
|
||||
if(this.state.currentUser && !this.state.currentUser.email) {
|
||||
this.history.pushState(null, '/login');
|
||||
}
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
UserStore.unlisten(this.onChange);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user