Redirect user after login
This commit is contained in:
parent
d51f56fc60
commit
b096152658
@ -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)} />
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user