Skip to content

Commit

Permalink
feat: update hook
Browse files Browse the repository at this point in the history
Hook payload updated to pass login strategy (if overridden, this value will be something other than 'local'), and explicitly pass error if the login failed.
  • Loading branch information
julianlam committed Apr 7, 2021
1 parent f32ea17 commit f65d216
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/controllers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ authenticationController.login = async (req, res, next) => {
function continueLogin(strategy, req, res, next) {
passport.authenticate(strategy, async (err, userData, info) => {
if (err) {
plugins.hooks.fire('action:login.continue', { req, strategy, userData, error: err });
return helpers.noScriptErrors(req, res, err.message, 403);
}

Expand All @@ -271,6 +272,8 @@ function continueLogin(strategy, req, res, next) {
} else if (typeof info === 'object') {
info = '[[error:invalid-username-or-password]]';
}

plugins.hooks.fire('action:login.continue', { req, strategy, userData, error: new Error(info) });
return helpers.noScriptErrors(req, res, info, 403);
}

Expand All @@ -284,7 +287,7 @@ function continueLogin(strategy, req, res, next) {
req.session.cookie.expires = false;
}

plugins.hooks.fire('action:login.continue', { req, userData });
plugins.hooks.fire('action:login.continue', { req, strategy, userData, error: null });

if (userData.passwordExpiry && userData.passwordExpiry < Date.now()) {
winston.verbose(`[auth] Triggering password reset for uid ${userData.uid} due to password policy`);
Expand Down

0 comments on commit f65d216

Please sign in to comment.