refs #6434 feat: show error for wrong login

This commit is contained in:
Javier Segarra 2023-11-15 13:49:54 +01:00
parent e0f6d08a1e
commit 0a31968cc7
1 changed files with 9 additions and 2 deletions

View File

@ -2,6 +2,7 @@ const vnModel = require('vn-loopback/common/models/vn-model');
const {Email} = require('vn-print');
const ForbiddenError = require('vn-loopback/util/forbiddenError');
const LoopBackContext = require('loopback-context');
const UserError = require('vn-loopback/util/user-error');
module.exports = function(Self) {
vnModel(Self);
@ -125,10 +126,16 @@ module.exports = function(Self) {
});
Self.validateLogin = async function(user, password) {
let loginInfo = Object.assign({password}, Self.userUses(user));
token = await Self.login(loginInfo, 'user');
const loginInfo = Object.assign({password}, Self.userUses(user));
const token = await Self.login(loginInfo, 'user');
const userToken = await token.user.get();
if (userToken.username !== user) {
console.error('ERROR!!! - Signin with other user', userToken, user);
throw new UserError('Try again');
}
try {
await Self.app.models.Account.sync(userToken.name, password);
} catch (err) {