fix(session): limit subqueries for mariadb

MariaDB does not support `connect-typeorm`s subqueries,
so they need to be disabled if this dialect is used.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-03-05 19:22:21 +01:00
parent 9c6d3d9dab
commit f9448bb801
3 changed files with 11 additions and 2 deletions

View file

@ -10,16 +10,20 @@ import session from 'express-session';
import { Repository } from 'typeorm';
import { AuthConfig } from '../config/auth.config';
import { DatabaseDialect } from '../config/database-dialect.enum';
import { DatabaseConfig } from '../config/database.config';
import { Session } from '../users/session.entity';
/**
* Setup 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.
*/
export function setupSessionMiddleware(
app: INestApplication,
authConfig: AuthConfig,
dbConfig: DatabaseConfig,
): void {
app.use(
session({
@ -32,6 +36,7 @@ export function setupSessionMiddleware(
saveUninitialized: false,
store: new TypeormStore({
cleanupLimit: 2,
limitSubquery: dbConfig.dialect !== DatabaseDialect.MARIADB,
}).connect(app.get<Repository<Session>>(getRepositoryToken(Session))),
}),
);