Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@constlab/vesper-jwt-auth

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@constlab/vesper-jwt-auth - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

9

dist/service/AuthService.d.ts

@@ -52,2 +52,11 @@ import { IUser } from "../base/IUser";

clearAllTokens(user: IUser): Promise<DeleteResult>;
/**
* Check for maximum saved tokens
*
* @protected
* @param {IUser} user
* @returns {Promise<void>}
* @memberof AuthService
*/
protected checkForMaximum(user: IUser): Promise<void>;
}

45

dist/service/AuthService.js

@@ -104,19 +104,20 @@ "use strict";

async saveToken(user, userAgent, refreshToken) {
const tokensCount = await this.entityManager.count(Token_1.Token, {
where: { userId: user.id.toString() }
await this.checkForMaximum(user);
const savedToken = await this.entityManager.findOne(Token_1.Token, {
where: {
client: userAgent,
userId: user.id.toString()
}
});
if (tokensCount + 1 >= this.config.refreshToken.maxSavedTokens) {
await this.clearAllTokens(user);
if (savedToken !== undefined) {
savedToken.token = refreshToken;
return await this.entityManager.save(savedToken);
}
else {
await this.entityManager.delete(Token_1.Token, {
client: userAgent,
userId: user.id.toString()
});
const newToken = new Token_1.Token();
newToken.client = userAgent;
newToken.token = refreshToken;
newToken.userId = user.id.toString();
return await this.entityManager.save(Token_1.Token, newToken);
}
const newToken = new Token_1.Token();
newToken.client = userAgent;
newToken.token = refreshToken;
newToken.userId = user.id.toString();
return await this.entityManager.save(Token_1.Token, newToken);
}

@@ -135,2 +136,18 @@ /**

}
/**
* Check for maximum saved tokens
*
* @protected
* @param {IUser} user
* @returns {Promise<void>}
* @memberof AuthService
*/
async checkForMaximum(user) {
const tokensCount = await this.entityManager.count(Token_1.Token, {
where: { userId: user.id.toString() }
});
if (tokensCount + 1 >= this.config.refreshToken.maxSavedTokens) {
await this.clearAllTokens(user);
}
}
};

@@ -146,2 +163,2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UFBRSxDQUFDLFFBQVEsRUFBRTtTQUMxQixDQUFDLENBQUM7SUFDSixDQUFDO0lBRUQ7Ozs7Ozs7T0FPRztJQUNPLEtBQUssQ0FBQyxlQUFlLENBQUMsSUFBVztRQUMxQyxNQUFNLFdBQVcsR0FBVyxNQUFNLElBQUksQ0FBQyxhQUFhLENBQUMsS0FBSyxDQUFDLGFBQUssRUFBRTtZQUNqRSxLQUFLLEVBQUUsRUFBRSxNQUFNLEVBQUUsSUFBSSxDQUFDLEVBQUUsQ0FBQyxRQUFRLEVBQUUsRUFBRTtTQUNyQyxDQUFDLENBQUM7UUFDSCxJQUFJLFdBQVcsR0FBRyxDQUFDLElBQUksSUFBSSxDQUFDLE1BQU0sQ0FBQyxZQUFZLENBQUMsY0FBYyxFQUFFO1lBQy9ELE1BQU0sSUFBSSxDQUFDLGNBQWMsQ0FBQyxJQUFJLENBQUMsQ0FBQztTQUNoQztJQUNGLENBQUM7Q0FDRCxDQUFBO0FBN0lBO0lBREMsZUFBTSxDQUFDLGlCQUFpQixDQUFDOzttREFDZTtBQUY3QixXQUFXO0lBRHZCLGdCQUFPLEVBQUU7cURBUWUsdUJBQWE7R0FQekIsV0FBVyxDQStJdkI7QUEvSVksa0NBQVcifQ==
{
"name": "@constlab/vesper-jwt-auth",
"version": "0.0.5",
"version": "0.0.6",
"description": "vesper + jwt auth",

@@ -12,3 +12,4 @@ "main": "dist/index.js",

"build": "NODE_ENV=prod rm -rf dist/* && tsc && (cd src/ && find . -name '*.gql' | cpio -pdm ../dist/)",
"test": "echo \"No test specified\" && exit 0"
"test": "echo \"No test specified\" && exit 0",
"clean-publish": "clean-publish"
},

@@ -43,3 +44,4 @@ "keywords": [

"@types/jsonwebtoken": "^7.2.8",
"@types/node": "^10.7.0",
"@types/node": "^10.7.1",
"clean-publish": "^1.0.9",
"conventional-changelog-cli": "^2.0.1",

@@ -46,0 +48,0 @@ "sqlite3": "^4.0.2",

@@ -109,20 +109,22 @@ import * as jwt from "jsonwebtoken";

async saveToken(user: IUser, userAgent: string, refreshToken: string): Promise<Token> {
const tokensCount: number = await this.entityManager.count(Token, {
where: { userId: user.id.toString() }
});
if (tokensCount + 1 >= this.config.refreshToken.maxSavedTokens) {
await this.clearAllTokens(user);
} else {
await this.entityManager.delete(Token, {
await this.checkForMaximum(user);
const savedToken = await this.entityManager.findOne(Token, {
where: {
client: userAgent,
userId: user.id.toString()
});
}
}
});
if (savedToken !== undefined) {
savedToken.token = refreshToken;
const newToken = new Token();
newToken.client = userAgent;
newToken.token = refreshToken;
newToken.userId = user.id.toString();
return await this.entityManager.save(savedToken);
} else {
const newToken = new Token();
newToken.client = userAgent;
newToken.token = refreshToken;
newToken.userId = user.id.toString();
return await this.entityManager.save(Token, newToken);
return await this.entityManager.save(Token, newToken);
}
}

@@ -142,2 +144,19 @@

}
/**
* Check for maximum saved tokens
*
* @protected
* @param {IUser} user
* @returns {Promise<void>}
* @memberof AuthService
*/
protected async checkForMaximum(user: IUser): Promise<void> {
const tokensCount: number = await this.entityManager.count(Token, {
where: { userId: user.id.toString() }
});
if (tokensCount + 1 >= this.config.refreshToken.maxSavedTokens) {
await this.clearAllTokens(user);
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc