diff --git a/back/methods/vn-user/sign-in.js b/back/methods/vn-user/sign-in.js index 9c2d568f4..be48ef78c 100644 --- a/back/methods/vn-user/sign-in.js +++ b/back/methods/vn-user/sign-in.js @@ -49,13 +49,7 @@ module.exports = Self => { if (vnUser.twoFactor) throw new ForbiddenError(null, 'REQUIRES_2FA'); } - const validateLogin = await Self.validateLogin(user, password); - await Self.app.models.SignInLog.create({ - token: validateLogin.token, - userFk: vnUser.id, - ip: ctx.req.ip - }); - return validateLogin; + return Self.validateLogin(user, password); }; Self.passExpired = async vnUser => { diff --git a/back/models/vn-user.js b/back/models/vn-user.js index e73c04bc0..8911bf954 100644 --- a/back/models/vn-user.js +++ b/back/models/vn-user.js @@ -126,6 +126,7 @@ module.exports = function(Self) { }); Self.signInValidate = (user, userToken) => { const [[key, value]] = Object.entries(Self.userUses(user)); + if (userToken[key].toLowerCase() !== value.toLowerCase()) { console.error('ERROR!!! - Signin with other user', userToken, user); throw new UserError('Try again'); @@ -137,6 +138,12 @@ module.exports = function(Self) { const token = await Self.login(loginInfo, 'user'); const userToken = await token.user.get(); + + await Self.app.models.SignInLog.create({ + token: token.id, + userFk: userToken.id, + ip: ctx.req.ip + }); Self.signInValidate(user, userToken); try {