Skip to content

Commit

Permalink
Route to controlled next path after local login
Browse files Browse the repository at this point in the history
  • Loading branch information
gocreating committed Oct 24, 2016
1 parent 2312510 commit 1a9d027
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/common/components/forms/LoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ class LoginForm extends Component {
if (json.isAuth) {
this.login(json).then(() => {
// redirect to the origin path before logging in
const { location } = this.props;
if (location && location.state && location.state.nextPathname) {
dispatch(push(location.state.nextPathname));
} else {
dispatch(push('/'));
}
let { next } = this.props.routing.locationBeforeTransitions.query;
dispatch(push(next || '/'));
});
} else {
dispatch(pushErrors([{
Expand Down Expand Up @@ -110,4 +106,5 @@ export default reduxForm({
validate,
})(connect(state => ({
apiEngine: state.apiEngine,
routing: state.routing,
}))(LoginForm));
4 changes: 2 additions & 2 deletions src/common/utils/authRequired.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export default (store) => (nextState, replace) => {
if (!token) {
replace({
pathname: '/user/login',
state: {
nextPathname: nextState.location.pathname,
query: {
next: nextState.location.pathname,
},
});
}
Expand Down

0 comments on commit 1a9d027

Please sign in to comment.