diff --git a/file.js b/file.js index b02918b..08dcda2 100644 --- a/file.js +++ b/file.js @@ -177,7 +177,7 @@ class Authenticator { async verifyToken(token) { if (jwt.verify(token, this.JWT_SECRET_KEY, this.JWT_OPTIONS)) { let jwt_token = jwt.decode(token); - return (this.getInfoFromUser(jwt_token._id).jwt_version == jwt_token.version); + return (this.getInfoFromUser(jwt_token._id).version == jwt_token.version) ? this.getInfoFromUser(jwt_token._id) : false; } } async verify2FA(userId, twofactorcode) { diff --git a/file.test.js b/file.test.js index f708b66..308ad41 100644 --- a/file.test.js +++ b/file.test.js @@ -101,7 +101,7 @@ describe('Authenticator Class Tests', () => { test('Verify JWT Token', async () => { const loginResult = await authenticator.login(mockUser.email, mockUser.password); const tokenVerification = await authenticator.verifyToken(loginResult.jwt_token); - expect(tokenVerification).toBe(true); + expect(tokenVerification).toBeDefined() }); test('Verify 2FA code', async () => { diff --git a/memory.js b/memory.js index 9e6c470..64c150b 100644 --- a/memory.js +++ b/memory.js @@ -123,7 +123,7 @@ class Authenticator { async verifyToken(token) { if (jwt.verify(token, this.JWT_SECRET_KEY, this.JWT_OPTIONS)) { let jwt_token = jwt.decode(token); - return (this.getInfoFromUser(jwt_token._id).jwt_version == jwt_token.version); + return (this.getInfoFromUser(jwt_token._id).version == jwt_token.version) ? this.getInfoFromUser(jwt_token._id) : false; } } async verify2FA(userId, twofactorcode) { diff --git a/memory.test.js b/memory.test.js index 843bc36..7e4dba0 100644 --- a/memory.test.js +++ b/memory.test.js @@ -100,7 +100,7 @@ describe('Authenticator Class Tests', () => { test('Verify JWT Token', async () => { const loginResult = await authenticator.login(mockUser.email, mockUser.password); const tokenVerification = await authenticator.verifyToken(loginResult.jwt_token); - expect(tokenVerification).toBe(true); + expect(tokenVerification).toBeDefined() }); test('Verify 2FA code', async () => { diff --git a/mongodb.js b/mongodb.js index 17bd8e0..053368d 100644 --- a/mongodb.js +++ b/mongodb.js @@ -147,13 +147,7 @@ class Authenticator { try { if (jwt.verify(token, this.JWT_SECRET_KEY, this.JWT_OPTIONS)) { let jwt_token = jwt.decode(token); - let user = await this.getInfoFromUser(jwt_token.id) - - if (user.jwt_version == jwt_token.version) { - return true - } else { - return false - } + return (this.getInfoFromUser(jwt_token._id).version == jwt_token.version) ? this.getInfoFromUser(jwt_token._id) : false; } } catch (error) { console.log(error) diff --git a/mongodb.test.js b/mongodb.test.js index 7c1e807..1c2c47e 100644 --- a/mongodb.test.js +++ b/mongodb.test.js @@ -108,7 +108,7 @@ describe('Authenticator Class Tests', () => { test('Verify JWT Token', async () => { const loginResult = await authenticator.login(mockUser.email, mockUser.password); const tokenVerification = await authenticator.verifyToken(loginResult.jwt_token); - expect(tokenVerification).toBe(true); + expect(tokenVerification).toBeDefined() }); test('Verify 2FA code', async () => { diff --git a/package.json b/package.json index a6e02fb..33fa687 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "seamless-auth", - "version": "3.7.4", + "version": "3.7.5", "description": "A full fledged authentication system...", "type": "commonjs", "main": "memory.js",