Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip redirect on password module when request is xhr #444

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/modules/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ everyModule.submodule('password')
.promises(null)
.step('respondToLoginSucceed') // TODO Rename to maybeRespondToLoginSucceed ?
.description('Execute a HTTP response for a successful login')
.accepts('res user')
.accepts('req res user')
.promises(null)
.step('respondToLoginFail')
.description('Execute a HTTP response for a failed login')
Expand All @@ -203,9 +203,13 @@ everyModule.submodule('password')
_auth.userId = user[this._userPkey];
_auth.loggedIn = !!user;
})
.respondToLoginSucceed( function (res, user) {
.respondToLoginSucceed( function (req, res, user) {
if (user) {
this.redirect(res, this.loginSuccessRedirect());
if (req.xhr) {
res.status(200).send();
} else {
this.redirect(res, this.loginSuccessRedirect());
}
}
})
.respondToLoginFail( function (req, res, errors, login) {
Expand Down Expand Up @@ -326,7 +330,11 @@ everyModule.submodule('password')
return user;
})
.respondToRegistrationSucceed( function (req, res, user) {
this.redirect(res, this.registerSuccessRedirect());
if (req.xhr) {
res.status(200).send();
} else {
this.redirect(res, this.registerSuccessRedirect());
}
})

.stepseq('registrationFailSteps')
Expand Down