
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@rabithua/prisma-session-store
Advanced tools
A modern Prisma-based session store for Express with TypeScript support and automatic cleanup
A modern, TypeScript-first session store for Express.js using Prisma ORM with automatic cleanup functionality.
npm install @rabithua/prisma-session-store
# or
yarn add @rabithua/prisma-session-store
# or
pnpm add @rabithua/prisma-session-store
# or
bun add @rabithua/prisma-session-store
First, add the Session model to your Prisma schema:
model Session {
id String @id @default(cuid())
sid String @unique
data String
expiresAt DateTime
@@map("sessions")
}
Then run the migration:
npx prisma migrate dev
# or for MongoDB
npx prisma db push
import express from 'express';
import session from 'express-session';
import { PrismaClient } from '@prisma/client';
import { PrismaSessionStore } from '@rabithua/prisma-session-store';
const app = express();
const prisma = new PrismaClient();
app.use(session({
store: new PrismaSessionStore({
prisma: prisma,
checkPeriod: 2 * 60 * 1000, // 2 minutes
}),
secret: 'your-secret-key',
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 7 // 1 week
}
}));
app.listen(3000);
interface PrismaSessionStoreOptions {
/**
* Prisma client instance (required)
*/
prisma: PrismaClient;
/**
* Cleanup check period in milliseconds
* @default 120000 (2 minutes)
*/
checkPeriod?: number;
/**
* Session table name (if using custom table name)
* @default 'session'
*/
tableName?: string;
/**
* Enable automatic cleanup of expired sessions
* @default true
*/
autoCleanup?: boolean;
/**
* Default session TTL in milliseconds
* @default 2678400000 (31 days)
*/
defaultTtl?: number;
}
If you're using a different table name in your schema:
// In your schema.prisma
model UserSession {
id String @id @default(cuid())
sid String @unique
data String
expiresAt DateTime
@@map("user_sessions")
}
// In your application
const store = new PrismaSessionStore({
prisma: prisma,
tableName: 'userSession', // Use the model name, not the table name
});
const store = new PrismaSessionStore({
prisma: prisma,
autoCleanup: false, // Disable automatic cleanup
});
// Manual cleanup
const result = await store.cleanup();
console.log(`Cleaned up ${result.deletedCount} expired sessions`);
const store = new PrismaSessionStore({ prisma });
// Stop automatic cleanup
store.stopCleanup();
// Restart automatic cleanup
store.startCleanup();
get(sid, callback)Retrieve a session by session ID.
set(sid, session, callback)Store or update a session.
destroy(sid, callback)Destroy a session.
touch(sid, session, callback)Update the expiration time of a session.
all(callback)Retrieve all active sessions.
length(callback)Get the count of active sessions.
clear(callback)Clear all sessions.
cleanup()Manually cleanup expired sessions. Returns a promise with the number of deleted sessions.
startCleanup()Start automatic cleanup of expired sessions.
stopCleanup()Stop automatic cleanup.
The store handles various error conditions gracefully:
This session store works with all databases supported by Prisma:
sid field is indexed for fast lookupsThis package is designed as a drop-in replacement for @quixo3/prisma-session-store with additional features:
// Before
import { PrismaSessionStore } from '@quixo3/prisma-session-store';
// After
import { PrismaSessionStore } from '@rabithua/prisma-session-store';
// The API is compatible, just pass the prisma instance
const store = new PrismaSessionStore({
prisma: prismaClient,
checkPeriod: 2 * 60 * 1000,
});
We welcome contributions! Please see our Contributing Guide for details.
MIT License - see the LICENSE file for details.
Made with ❤️ by rabithua
FAQs
A modern Prisma-based session store for Express with TypeScript support and automatic cleanup
We found that @rabithua/prisma-session-store demonstrated a healthy version release cadence and project activity because the last version was released less than 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.