mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 13:19:44 +02:00
feat: Ability to show detailed auth errors, set to false by default (#860)
This commit is contained in:
parent
573e6b65ba
commit
ccfc621d51
7 changed files with 29 additions and 2 deletions
|
@ -4,6 +4,9 @@ const validator = require('validator');
|
|||
const { getRemoteAddress } = require('../../../utils/remoteAddress');
|
||||
|
||||
const Errors = {
|
||||
INVALID_CREDENTIALS: {
|
||||
invalidCredentials: 'Invalid credentials',
|
||||
},
|
||||
INVALID_EMAIL_OR_USERNAME: {
|
||||
invalidEmailOrUsername: 'Invalid email or username',
|
||||
},
|
||||
|
@ -34,6 +37,9 @@ module.exports = {
|
|||
},
|
||||
|
||||
exits: {
|
||||
invalidCredentials: {
|
||||
responseType: 'unauthorized',
|
||||
},
|
||||
invalidEmailOrUsername: {
|
||||
responseType: 'unauthorized',
|
||||
},
|
||||
|
@ -57,7 +63,10 @@ module.exports = {
|
|||
sails.log.warn(
|
||||
`Invalid email or username: "${inputs.emailOrUsername}"! (IP: ${remoteAddress})`,
|
||||
);
|
||||
throw Errors.INVALID_EMAIL_OR_USERNAME;
|
||||
|
||||
throw sails.config.custom.showDetailedAuthErrors
|
||||
? Errors.INVALID_EMAIL_OR_USERNAME
|
||||
: Errors.INVALID_CREDENTIALS;
|
||||
}
|
||||
|
||||
if (user.isSso) {
|
||||
|
@ -66,7 +75,10 @@ module.exports = {
|
|||
|
||||
if (!bcrypt.compareSync(inputs.password, user.password)) {
|
||||
sails.log.warn(`Invalid password! (IP: ${remoteAddress})`);
|
||||
throw Errors.INVALID_PASSWORD;
|
||||
|
||||
throw sails.config.custom.showDetailedAuthErrors
|
||||
? Errors.INVALID_PASSWORD
|
||||
: Errors.INVALID_CREDENTIALS;
|
||||
}
|
||||
|
||||
const accessToken = sails.helpers.utils.createToken(user.id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue