1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-03 18:35:09 +01:00
onion/js/components/ascribe_routes/auth_component.js
Tim Daubenschütz 28dfcfa75a Merge remote-tracking branch 'origin/master' into AD-727-missing-redirects-to-login-page
Conflicts:
	js/components/ascribe_detail/edition.js
	js/components/ascribe_forms/form_login.js
	js/components/ascribe_forms/form_signup.js
2015-10-06 16:40:02 +02:00

44 lines
1013 B
JavaScript

'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();
},
componentDidMount() {
UserStore.listen(this.onChange);
UserActions.fetchCurrentUser();
},
componentDidUpdate() {
if(this.state.currentUser && !this.state.currentUser.email) {
console.log('redirect');
this.history.pushState(null, '/login');
}
},
componentWillUnmount() {
UserStore.unlisten(this.onChange);
},
onChange(state) {
this.setState(state);
},
render() {
return (
<Component {...this.props}/>
);
}
});
}