1
0
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:
Tim Daubenschütz 2015-10-06 15:38:39 +02:00
parent 6877f2c8a7
commit 0c6538df2f

View File

@ -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);
},