Skip to content

Commit

Permalink
now returning user after verifying token
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPlayGamez committed Oct 2, 2024
1 parent b4fa052 commit d2a40a1
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion memory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
8 changes: 1 addition & 7 deletions mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mongodb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit d2a40a1

Please sign in to comment.