diff --git a/back/methods/account/login.js b/back/methods/account/login.js index 47d4d629a..2f6a04893 100644 --- a/back/methods/account/login.js +++ b/back/methods/account/login.js @@ -64,7 +64,7 @@ module.exports = Self => { } } - if (account.twoFactor === 'email') { + if (account && account.twoFactor === 'email') { const authAccess = await $.UserAccess.findOne({ where: { userFk: account.id, diff --git a/back/methods/account/specs/login.spec.js b/back/methods/account/specs/login.spec.js index 59eea2612..a51f6b91e 100644 --- a/back/methods/account/specs/login.spec.js +++ b/back/methods/account/specs/login.spec.js @@ -1,9 +1,10 @@ const app = require('vn-loopback/server/server'); describe('account login()', () => { + const unauthCtx = {}; describe('when credentials are correct', () => { it('should return the token', async() => { - let login = await app.models.Account.login('salesAssistant', 'nightmare'); + let login = await app.models.Account.login(unauthCtx, 'salesAssistant', 'nightmare'); let accessToken = await app.models.AccessToken.findById(login.token); let ctx = {req: {accessToken: accessToken}}; @@ -13,7 +14,7 @@ describe('account login()', () => { }); it('should return the token if the user doesnt exist but the client does', async() => { - let login = await app.models.Account.login('PetterParker', 'nightmare'); + let login = await app.models.Account.login(unauthCtx, 'PetterParker', 'nightmare'); let accessToken = await app.models.AccessToken.findById(login.token); let ctx = {req: {accessToken: accessToken}}; @@ -28,7 +29,7 @@ describe('account login()', () => { let error; try { - await app.models.Account.login('IDontExist', 'TotallyWrongPassword'); + await app.models.Account.login(unauthCtx, 'IDontExist', 'TotallyWrongPassword'); } catch (e) { error = e; } diff --git a/back/methods/account/specs/logout.spec.js b/back/methods/account/specs/logout.spec.js index b3d69d6ef..5acbf90df 100644 --- a/back/methods/account/specs/logout.spec.js +++ b/back/methods/account/specs/logout.spec.js @@ -2,7 +2,8 @@ const app = require('vn-loopback/server/server'); describe('account logout()', () => { it('should logout and remove token after valid login', async() => { - let loginResponse = await app.models.Account.login('buyer', 'nightmare'); + const unauthCtx = {}; + let loginResponse = await app.models.Account.login(unauthCtx, 'buyer', 'nightmare'); let accessToken = await app.models.AccessToken.findById(loginResponse.token); let ctx = {req: {accessToken: accessToken}};