From 654efcc3505c0713079ae61935031f157bc44dd2 Mon Sep 17 00:00:00 2001 From: Mohamed Marrouchi Date: Tue, 25 Dec 2018 15:44:52 +0100 Subject: [PATCH] Pass SAError when user identifier does not exist This would be very helpful especially for debuging when req.flash is not used (API app). Currently, if user does not exist the the request response and the console return both "null". --- api/services/protocols/local.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/api/services/protocols/local.js b/api/services/protocols/local.js index ed0f22b..70cfd78 100644 --- a/api/services/protocols/local.js +++ b/api/services/protocols/local.js @@ -198,13 +198,9 @@ exports.login = function (req, identifier, password, next) { } if (!user) { - if (isEmail) { - req.flash('error', 'Error.Passport.Email.NotFound'); - } else { - req.flash('error', 'Error.Passport.Username.NotFound'); - } - - return next(null, false); + var message = sails.__((isEmail) ? 'Error.Passport.Email.NotFound' : 'Error.Passport.Username.NotFound'); + req.flash('error', message); + return next(new SAError({message}), false); } sails.models.passport.findOne({