Skip to content

Commit a8e6c09

Browse files
committed
add: add new code related to authentication
- right now the code is commented, but we can use that in future
1 parent 3322174 commit a8e6c09

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/auth/guards/auth.guard.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,38 @@ export class JwtAuthGuard extends AuthGuard('jwt') implements CanActivate {
88
return super.canActivate(context);
99
}
1010
}
11+
12+
// import { CanActivate, ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common';
13+
// import { JwtService } from '@nestjs/jwt';
14+
// import { Request } from 'express';
15+
16+
// @Injectable()
17+
// export class AuthGuard implements CanActivate {
18+
// constructor(private jwtService: JwtService) {}
19+
20+
// async canActivate(context: ExecutionContext): Promise<boolean> {
21+
// const request = context.switchToHttp().getRequest();
22+
23+
// const token = this.extractTokenFromHeader(request);
24+
// if (!token) {
25+
// throw new UnauthorizedException();
26+
// }
27+
28+
// request['user'] = await this.verifyToken(token);
29+
// return true;
30+
// }
31+
32+
// private extractTokenFromHeader(request: Request): string | undefined {
33+
// const [type, token] = request.headers.authorization?.split(' ') ?? [];
34+
// return type === 'Bearer' ? token : undefined;
35+
// }
36+
37+
// private async verifyToken(token: string): Promise<{ id: string }> {
38+
// try {
39+
// const payload = await this.jwtService.verifyAsync(token);
40+
// return { id: payload.sub };
41+
// } catch {
42+
// throw new UnauthorizedException();
43+
// }
44+
// }
45+
// }

src/prisma-connection/prisma-connection.module.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,17 @@ import { PrismaConnectionService } from './prisma-connection.service';
99
exports: [PrismaConnectionService],
1010
})
1111
export class PrismaConnectionModule {}
12+
13+
//! Below part is used when we have error this
14+
//? ==>> some worker can't close properly and force exited and exit gracefully. This is likely caused by tests leaking due to improper teardown.
15+
//! and the above thing can be happen anywhere
16+
// export class PrismaConnectionModule implements OnApplicationShutdown {
17+
// constructor(
18+
// @Inject('')
19+
// private readonly prismaClient: PrismaClient
20+
// ) {}
21+
22+
// onApplicationShutdown() {
23+
// this.prismaClient.$disconnect();
24+
// }
25+
// }

0 commit comments

Comments
 (0)