Skip to content

Commit 67f6134

Browse files
sru-thybharathkeyvalue
authored andcommitted
FIX: make execution context binder injectable
1 parent 2900db2 commit 67f6134

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/authentication/authentication.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,6 @@ const providers: Provider[] = [
7777
],
7878
providers,
7979
controllers: [GoogleAuthController],
80+
exports: [AuthenticationHelper],
8081
})
8182
export class UserAuthModule {}
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
import { NestMiddleware } from '@nestjs/common';
2-
import { NextFunction, Request, Response } from 'express';
3-
4-
import { ExecutionManager } from '../util/execution.manager';
1+
import { Injectable, NestMiddleware } from '@nestjs/common';
2+
import { Request, Response, NextFunction } from 'express';
53
import { AuthenticationHelper } from '../authentication/authentication.helper';
4+
import { ExecutionManager } from '../util/execution.manager';
65

6+
@Injectable()
77
export class ExecutionContextBinder implements NestMiddleware {
88
constructor(private readonly auth: AuthenticationHelper) {}
99
async use(req: Request, res: Response, next: NextFunction) {
1010
ExecutionManager.runWithContext(async () => {
11-
const token = req.headers.authorization?.split(' ')[1];
12-
if (token) {
13-
const user = this.auth.validateAuthToken(token);
14-
ExecutionManager.setTenantId(user.tenantId);
11+
try {
12+
const token = req.headers.authorization?.split(' ')[1];
13+
if (token) {
14+
const user = this.auth.validateAuthToken(token);
15+
ExecutionManager.setTenantId(user.tenantId);
16+
}
17+
next();
18+
} catch (error) {
19+
next(error);
1520
}
16-
next();
1721
});
1822
}
1923
}

0 commit comments

Comments
 (0)