Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@freshgiammi/connect-typeorm
Advanced tools
A TypeORM-based session store.
Configure TypeORM with back end of your choice:
npm install @freshgiammi/connect-typeorm express-session typeorm sqlite3
npm install -D @types/express-session
Session
entity:// src/domain/Session/Session.ts
import { ISession } from "connect-typeorm";
import { Column, DeleteDateColumn, Entity, Index, PrimaryColumn } from "typeorm";
@Entity()
export class Session implements ISession {
@Index()
@Column("bigint")
public expiredAt = Date.now();
@PrimaryColumn("varchar", { length: 255 })
public id = "";
@Column("text")
public json = "";
@DeleteDateColumn()
public destroyedAt?: Date;
}
Pass repository to TypeormStore
:
// src/app/Api/Api.ts
import { TypeormStore } from "connect-typeorm";
import { getRepository } from "typeorm";
import * as Express from "express";
import * as ExpressSession from "express-session";
import { Session } from "../../domain/Session/Session";
export class Api {
public sessionRepository = getRepository(Session);
public express = Express().use(
ExpressSession({
resave: false,
saveUninitialized: false,
store: new TypeormStore({
cleanupLimit: 2,
limitSubquery: false, // If using MariaDB.
ttl: 86400
}).connect(this.sessionRepository),
secret: "keyboard cat"
})
);
}
TypeORM uses { "bigNumberStrings": true }
option by default for node-mysql,
you can use a Transformer to fix this issue:
import { Bigint } from "typeorm-static";
@Column("bigint", { transformer: Bigint })
Constructor receives an object. Following properties may be included:
cleanupLimit
For every new session, remove this many expired ones (does not distinguish between users, so User A logging in can delete User B expired sessions). Defaults to 0, in case you need to analyze sessions retrospectively.
limitSubquery
Select and delete expired sessions in one query. Defaults to true, you can set false to make two queries, in case you want cleanupLimit but your MariaDB version doesn't support limit in a subquery.
ttl
Session time to live (expiration) in seconds. Defaults to session.maxAge (if set), or one day. This may also be set to a function of the form (store, sess, sessionID) => number
.
onError
Error handler for database exception. It is a function of the form (store: TypeormStore, error: Error) => void
. If not set, any database error will cause the TypeormStore to be marked as "disconnected", and stop reading/writing to the database, therefore not loading sessions and causing all requests to be considered unauthenticated.
MIT
FAQs
A TypeORM-based session store
The npm package @freshgiammi/connect-typeorm receives a total of 0 weekly downloads. As such, @freshgiammi/connect-typeorm popularity was classified as not popular.
We found that @freshgiammi/connect-typeorm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.