🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

typeorm-store

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeorm-store

A TypeORM-based store for express-session

2.0.1
latest
Source
npm
Version published
Weekly downloads
412
-18.9%
Maintainers
1
Weekly downloads
 
Created
Source

typeorm-store

A TypeORM-based store for express-session.

Installation

$ yarn add typeorm-store

Usage

First, make a new Session entity. Make sure to synchronize the entity to the database. typeorm-store will not to this for you.

import { BaseEntity, Column, Entity, PrimaryColumn } from 'typeorm';
import { SessionEntity } from 'typeorm-store';

@Entity()
export class Session extends BaseEntity implements SessionEntity {
    @PrimaryColumn()
    id: string;

    @Column()
    expiresAt: number;

    @Column()
    data: string;
}

Use TypeormStore as store in express-session, specifying the repository of the new Session entity.

import * as express from 'express';
import * as session from 'express-session';
import { getConnection } from 'typeorm';
import { TypeormStore } from 'typeorm-store';
import { Session } from './entities/session';

const app = express();

// Make sure the connection is ready before doing this
const repository = getConnection().getRepository(Session);

app.use(session({
   secret: 'secret',
   resave: false,
   saveUninitialized: false,
   store: new TypeormStore({ repository })
}))

API

new TypeormStore(options)

Options

  • repository (required) - The repository of the session entity.
  • ttl (optional) - The time to live for the session in seconds. Defaults to 86400 (1 day).
  • expirationInterval (optional) - The interval in seconds to check for expired sessions. Defaults to 86400 (1 minute).

FAQs

Package last updated on 03 Aug 2022

Did you know?

Socket

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.

Install

Related posts