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

@universal-packages/express-session

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@universal-packages/express-session - npm Package Compare versions

Comparing version 1.6.12 to 1.7.0

4

package.json
{
"name": "@universal-packages/express-session",
"version": "1.6.12",
"version": "1.7.0",
"description": "Express session manager.",

@@ -32,3 +32,3 @@ "author": "David De Anda <david@universal-packages.com> (https://github.com/universal-packages)",

"@universal-packages/fetch-jest": "^1.2.1",
"@universal-packages/maintenance": "^1.6.5",
"@universal-packages/maintenance": "^1.6.9",
"jest": "^29.7.0",

@@ -35,0 +35,0 @@ "prettier": "^3.0.3",

@@ -70,3 +70,3 @@ # Express Session

if (request.session.authenticated) {
request.currentUser = await User.find(request.session.authenticatableID)
request.currentUser = await User.find(request.session.userId)

@@ -90,3 +90,3 @@ next()

app.get('/', async (request, response) => {
const currentUser = await User.find(request.session.authenticatableID)
const currentUser = await User.find(request.session.userID)

@@ -107,3 +107,3 @@ response.end()

#### authenticatableId `String`
#### userId `String`

@@ -138,5 +138,5 @@ The same id used to create the session at log in.

#### **`logIn(authenticatableID: String)`** `Async`
#### **`logIn(userID: String)`** `Async`
Creates a new session using the authenticatable id and sets the cookie `session` as well as the `Authorization` response header to return to the user when ending the response.
Creates a new session using the user id and sets the cookie `session` as well as the `Authorization` response header to return to the user when ending the response.

@@ -149,12 +149,12 @@ #### **`logOut(token? string)`** `Async`

Returns all the active sessions for the current session authenticatable.
Returns all the active sessions for the current session user.
### Static methods
#### **`activeSessions(authenticatableId: String, [options: Object])`** `Async`
#### **`activeSessions(userId: String, [options: Object])`** `Async`
Returns all the active sessions for the authenticatable id.
Returns all the active sessions for the user id.
- **`authenticatableId`** `String`
The id of the authenticatable to get the active sessions from.
- **`userId`** `String`
The id of the user to get the active sessions from.
- **`options`** `Object`

@@ -161,0 +161,0 @@ Same options as [Token Registry](https://github.com/universal-packages/universal-token-registry#options)

@@ -8,3 +8,3 @@ import { MemoryEngine, RegistryOptions } from '@universal-packages/token-registry';

authenticated: boolean;
authenticatableId: string;
userId: string;
token: string;

@@ -22,5 +22,5 @@ firstAccessed: Date;

constructor(request: Request, response: Response, options?: RegistryOptions);
static activeSessions(authenticatableId: string | number | bigint, options?: ExpressSessionOptions): Promise<Record<string, SessionRegistrySubject>>;
static activeSessions(userId: string | number | bigint, options?: ExpressSessionOptions): Promise<Record<string, SessionRegistrySubject>>;
prepare(): Promise<void>;
logIn(authenticatableId: string | number | bigint): Promise<void>;
logIn(userId: string | number | bigint): Promise<void>;
logOut(token?: string): Promise<void>;

@@ -27,0 +27,0 @@ activeSessions(): Promise<Record<string, SessionRegistrySubject>>;

@@ -12,3 +12,3 @@ "use strict";

this.authenticated = false;
this.authenticatableId = null;
this.userId = null;
this.token = null;

@@ -27,7 +27,7 @@ this.firstAccessed = null;

}
static async activeSessions(authenticatableId, options) {
static async activeSessions(userId, options) {
const finalOptions = { engine: exports.MEMORY_ENGINE, cookieName: 'session', ...options };
const engine = finalOptions.engine === 'memory' ? exports.MEMORY_ENGINE : finalOptions.engine;
const registry = new token_registry_1.Registry({ engine: engine, engineOptions: finalOptions.engineOptions, seed: finalOptions.registryId || finalOptions.seed });
const category = `auth-${authenticatableId}`;
const category = `auth-${userId}`;
return await registry.retrieveAll(category);

@@ -44,3 +44,3 @@ }

this.authenticated = true;
this.authenticatableId = subject.authenticatableId;
this.userId = subject.userId;
this.firstAccessed = new Date(subject.firstAccessed);

@@ -53,3 +53,3 @@ this.lastAccessed = new Date();

if (this.options.trackSessionAccess) {
const category = `auth-${subject.authenticatableId}`;
const category = `auth-${subject.userId}`;
await this.registry.register(token, {

@@ -64,6 +64,6 @@ ...subject,

}
async logIn(authenticatableId) {
this.id = (0, crypto_utils_1.generateToken)({ seed: String(authenticatableId) });
async logIn(userId) {
this.id = (0, crypto_utils_1.generateToken)({ seed: String(userId) });
this.authenticated = true;
this.authenticatableId = String(authenticatableId);
this.userId = String(userId);
this.firstAccessed = new Date();

@@ -74,6 +74,6 @@ this.lastAccessed = new Date();

this.userAgent = this.request.headers['user-agent'];
const category = `auth-${authenticatableId}`;
const category = `auth-${userId}`;
this.token = await this.registry.register({
id: this.id,
authenticatableId: this.authenticatableId,
userId: this.userId,
firstAccessed: this.firstAccessed.getTime(),

@@ -99,3 +99,3 @@ lastAccessed: this.lastAccessed.getTime(),

this.token = null;
this.authenticatableId = null;
this.userId = null;
this.firstAccessed = null;

@@ -111,3 +111,3 @@ this.lastAccessed = null;

if (this.authenticated) {
const category = `auth-${this.authenticatableId}`;
const category = `auth-${this.userId}`;
return await this.registry.retrieveAll(category);

@@ -119,6 +119,6 @@ }

this.deviceId = deviceId;
const category = `auth-${this.authenticatableId}`;
const category = `auth-${this.userId}`;
await this.registry.register(this.token, {
id: this.id,
authenticatableId: this.authenticatableId,
userId: this.userId,
firstAccessed: this.firstAccessed.getTime(),

@@ -125,0 +125,0 @@ lastAccessed: this.lastAccessed.getTime(),

@@ -9,3 +9,3 @@ import { RegistryOptions } from '@universal-packages/token-registry';

id: string;
authenticatableId: string;
userId: string;
firstAccessed: number;

@@ -12,0 +12,0 @@ lastAccessed: number;

Sorry, the diff of this file is not supported yet

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