Redirect user after login

This commit is contained in:
Grégoire Delattre 2016-11-17 14:28:43 +01:00
parent d51f56fc60
commit b096152658
2 changed files with 13 additions and 1 deletions

View File

@ -78,7 +78,7 @@ ReactDOM.render((
<Provider store={store}>
<Router history={history}>
<Route path="/" component={App}>
<IndexRedirect to="/users/login" />
<IndexRedirect to="/movies/polochon" />
<Route path="/users/login" component={UserLoginForm} />
<Route path="/users/signup" component={UserSignUp} />
<Route path="/users/edit" component={UserIsAuthenticated(UserEdit)} />

View File

@ -5,6 +5,18 @@ export default class UserLoginForm extends React.Component {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
}
componentWillReceiveProps(nextProps) {
if (!nextProps.userStore.isLogged) {
return
}
if (!nextProps.location.query.redirect) {
// Redirect home
nextProps.router.push('/');
} else {
// Redirect to the previous page
nextProps.router.push(nextProps.location.query.redirect);
}
}
handleSubmit(e) {
e.preventDefault();
if (this.props.userStore.userLoading) {