mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 15:44:45 -04:00
refactor: move typeorm store into new session module
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
14ee7485ad
commit
57365bb727
16 changed files with 204 additions and 49 deletions
|
@ -4,40 +4,34 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { TypeormStore } from 'connect-typeorm';
|
||||
import session from 'express-session';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { AuthConfig } from '../config/auth.config';
|
||||
import { DatabaseType } from '../config/database-type.enum';
|
||||
import { DatabaseConfig } from '../config/database.config';
|
||||
import { Session } from '../users/session.entity';
|
||||
|
||||
export const HEDGEDOC_SESSION = 'hedgedoc-session';
|
||||
|
||||
/**
|
||||
* Setup the session middleware via the given authConfig.
|
||||
* Set up the session middleware via the given authConfig.
|
||||
* @param {INestApplication} app - the nest application to configure the middleware for.
|
||||
* @param {AuthConfig} authConfig - the authConfig to configure the middleware with.
|
||||
* @param {DatabaseConfig} dbConfig - the DatabaseConfig to configure the middleware with.
|
||||
* @param {TypeormStore} typeormStore - the typeormStore to handle session data.
|
||||
*/
|
||||
export function setupSessionMiddleware(
|
||||
app: INestApplication,
|
||||
authConfig: AuthConfig,
|
||||
dbConfig: DatabaseConfig,
|
||||
typeormStore: TypeormStore,
|
||||
): void {
|
||||
app.use(
|
||||
session({
|
||||
name: 'hedgedoc-session',
|
||||
name: HEDGEDOC_SESSION,
|
||||
secret: authConfig.session.secret,
|
||||
cookie: {
|
||||
maxAge: authConfig.session.lifetime,
|
||||
},
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
store: new TypeormStore({
|
||||
cleanupLimit: 2,
|
||||
limitSubquery: dbConfig.type !== DatabaseType.MARIADB,
|
||||
}).connect(app.get<Repository<Session>>(getRepositoryToken(Session))),
|
||||
store: typeormStore,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue