From f65d2162f8b16a7b7b1b8f2e8d004ff648e5329c Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 7 Apr 2021 14:21:45 -0400 Subject: [PATCH] feat: update hook 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. --- src/controllers/authentication.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js index f57eb185be..79cc5aa290 100644 --- a/src/controllers/authentication.js +++ b/src/controllers/authentication.js @@ -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); } @@ -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); } @@ -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`);