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

connect-mikro-orm

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-mikro-orm

A MikroORM-based session store

1.0.2
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

🔗 connect-mikro-orm

A MikroORM-based session store.


npm GitHub Repo stars

Setup & Usage

Configure MikroORM with back end of your choice:

NPM

yarn add connect-mikro-orm @mikro-orm/core @mikro-orm/knex express-session
yarn add -D @types/express-session

Implement the Session entity:

// src/domain/Session/Session.ts

import type { ISession } from 'connect-mikro-orm';

import { Entity, Index, PrimaryKey, Property } from '@mikro-orm/core';

@Entity()
export class Session implements ISession {
  @PrimaryKey()
  id: string;

  @Property({ columnType: 'text' })
  json: string;

  @Index()
  @Property({ columnType: 'bigint' })
  expiredAt: number;
}

Pass repository to MikroOrmStore:

// src/app/Api/Api.ts

import { MikroOrmStore } from 'connect-mikro-orm';
import * as Express from 'express';
import * as ExpressSession from 'express-session';

import { Session } from '../../domain/Session/Session';

export class Api {
  public sessionRepository = entityManager.getRepository(Session);

  public express = Express().use(
    ExpressSession({
      resave: false,
      saveUninitialized: false,
      store: new MikroOrmStore({
        ttl: 86400,
      }).connect(this.sessionRepository),
      secret: 'keyboard cat',
    })
  );
}

Options

Constructor receives an object. Following properties may be included:

  • 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: MikroOrmStore, error: Error) => void. If not set, any database error will cause the MikroOrmStore to be marked as "disconnected", and stop reading/writing to the database, therefore not loading sessions and causing all requests to be considered unauthenticated.

License

MIT

Keywords

mikro-orm

FAQs

Package last updated on 27 Feb 2023

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