diff --git a/js/components/ascribe_routes/auth_component.js b/js/components/ascribe_routes/auth_component.js index d761230e..7c5ec8ed 100644 --- a/js/components/ascribe_routes/auth_component.js +++ b/js/components/ascribe_routes/auth_component.js @@ -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); },