Skip to content

Commit 8e419f8

Browse files
committed
Run lint
1 parent 430d6ab commit 8e419f8

File tree

10 files changed

+49
-36
lines changed

10 files changed

+49
-36
lines changed

backend/src/app.module.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import { AuthMiddleware } from './auth/auth.middleware';
2323
})
2424
export class AppModule implements NestModule {
2525
configure(consumer: MiddlewareConsumer) {
26-
consumer
27-
.apply(AuthMiddleware)
28-
.forRoutes('*');
26+
consumer.apply(AuthMiddleware).forRoutes('*');
2927
}
3028
}

backend/src/auth/auth.middleware.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('AuthMiddleware', () => {
88

99
// Create a mock JwtService
1010
const mockJwtService = {
11-
verifyToken: vi.fn()
11+
verifyToken: vi.fn(),
1212
};
1313

1414
beforeEach(async () => {

backend/src/auth/auth.middleware.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export class AuthMiddleware implements NestMiddleware {
1414
const user = await this.jwtService.verifyToken(token);
1515
req.user = user;
1616
} catch (error: unknown) {
17-
console.error('Token validation failed:', error instanceof Error ? error.message : 'Unknown error');
17+
console.error(
18+
'Token validation failed:',
19+
error instanceof Error ? error.message : 'Unknown error',
20+
);
1821
}
1922
}
2023

backend/src/auth/get-user.decorator.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import { ExecutionContext } from '@nestjs/common';
2-
import { GetUser } from './get-user.decorator';
32
import { vi, describe, it, expect } from 'vitest';
43

54
// We need to mock the NestJS decorator factory
65
vi.mock('@nestjs/common', async () => {
76
const actual = await vi.importActual('@nestjs/common');
87
return {
9-
...actual as any,
10-
createParamDecorator: (factory: Function) => {
8+
...(actual as any),
9+
createParamDecorator: (factory: (data: any, ctx: ExecutionContext) => any) => {
1110
return (data?: string) => {
1211
return {
1312
factory,
14-
data
13+
data,
1514
};
1615
};
17-
}
16+
},
1817
};
1918
});
2019

@@ -80,7 +79,7 @@ describe('GetUser Decorator', () => {
8079
id: 'user123',
8180
8281
groups: ['users'],
83-
preferences: { theme: 'dark' }
82+
preferences: { theme: 'dark' },
8483
};
8584

8685
// Create mock context
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
22

3-
export const GetUser = createParamDecorator(
4-
(data: unknown, ctx: ExecutionContext) => {
5-
const request = ctx.switchToHttp().getRequest();
6-
return request.user;
7-
},
8-
);
3+
export const GetUser = createParamDecorator((data: unknown, ctx: ExecutionContext) => {
4+
const request = ctx.switchToHttp().getRequest();
5+
return request.user;
6+
});

backend/src/auth/jwt-auth.guard.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('JwtAuthGuard', () => {
99

1010
// Create a mock JwtService
1111
const mockJwtService = {
12-
verifyToken: vi.fn()
12+
verifyToken: vi.fn(),
1313
};
1414

1515
beforeEach(async () => {

backend/src/auth/jwt-auth.guard.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import { JwtService } from './jwt.service';
66
export class JwtAuthGuard implements CanActivate {
77
constructor(private jwtService: JwtService) {}
88

9-
canActivate(
10-
context: ExecutionContext,
11-
): boolean | Promise<boolean> | Observable<boolean> {
9+
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
1210
const request = context.switchToHttp().getRequest();
1311
const token = request.headers['x-amzn-oidc-data'];
1412

backend/src/auth/jwt.service.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface JWK {
88
alg: string;
99
e: string;
1010
kid: string;
11-
kty: "RSA";
11+
kty: 'RSA';
1212
n: string;
1313
use: string;
1414
}
@@ -40,7 +40,12 @@ export class JwtService {
4040
// Decode the token without verification to get the key ID (kid)
4141
const decodedToken = jwt.decode(token, { complete: true });
4242

43-
if (!decodedToken || typeof decodedToken !== 'object' || !decodedToken.header || !decodedToken.header.kid) {
43+
if (
44+
!decodedToken ||
45+
typeof decodedToken !== 'object' ||
46+
!decodedToken.header ||
47+
!decodedToken.header.kid
48+
) {
4449
throw new Error('Invalid token format');
4550
}
4651

@@ -56,20 +61,25 @@ export class JwtService {
5661

5762
// Verify the token
5863
const region = this.configService.get<string>('AWS_REGION', 'us-east-1');
59-
const userPoolId = this.configService.get<string>('COGNITO_USER_POOL_ID', 'ai-cognito-medical-reports-user-pool');
64+
const userPoolId = this.configService.get<string>(
65+
'COGNITO_USER_POOL_ID',
66+
'ai-cognito-medical-reports-user-pool',
67+
);
6068

6169
const verified = jwt.verify(token, pem, {
6270
algorithms: ['RS256'],
63-
issuer: `https://cognito-idp.${region}.amazonaws.com/${userPoolId}`
71+
issuer: `https://cognito-idp.${region}.amazonaws.com/${userPoolId}`,
6472
}) as DecodedToken;
6573

6674
return {
6775
id: verified.sub,
6876
email: verified.email,
69-
groups: verified['cognito:groups'] || []
77+
groups: verified['cognito:groups'] || [],
7078
};
7179
} catch (error: unknown) {
72-
this.logger.error(`Token verification failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
80+
this.logger.error(
81+
`Token verification failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
82+
);
7383
throw error;
7484
}
7585
}
@@ -78,13 +88,19 @@ export class JwtService {
7888
const now = Date.now();
7989

8090
// Return cached JWKs if they're still valid
81-
if (Object.keys(this.jwksCache).length > 0 && now - this.jwksCacheTime < this.JWKS_CACHE_DURATION) {
91+
if (
92+
Object.keys(this.jwksCache).length > 0 &&
93+
now - this.jwksCacheTime < this.JWKS_CACHE_DURATION
94+
) {
8295
return this.jwksCache;
8396
}
8497

8598
try {
8699
const region = this.configService.get<string>('AWS_REGION', 'us-east-1');
87-
const userPoolId = this.configService.get<string>('COGNITO_USER_POOL_ID', 'ai-cognito-medical-reports-user-pool');
100+
const userPoolId = this.configService.get<string>(
101+
'COGNITO_USER_POOL_ID',
102+
'ai-cognito-medical-reports-user-pool',
103+
);
88104
const jwksUrl = `https://cognito-idp.${region}.amazonaws.com/${userPoolId}/.well-known/jwks.json`;
89105

90106
const response = await axios.get<CognitoJWKS>(jwksUrl);
@@ -99,7 +115,9 @@ export class JwtService {
99115

100116
return jwks;
101117
} catch (error: unknown) {
102-
this.logger.error(`Error fetching JWKs: ${error instanceof Error ? error.message : 'Unknown error'}`);
118+
this.logger.error(
119+
`Error fetching JWKs: ${error instanceof Error ? error.message : 'Unknown error'}`,
120+
);
103121
throw new Error('Failed to fetch JWKs');
104122
}
105123
}

backend/src/auth/user.interface.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ export interface User {
55
}
66

77
// Extend Express Request interface to include user property
8-
declare global {
9-
namespace Express {
10-
interface Request {
11-
user?: User;
12-
}
8+
// Using module augmentation instead of namespace
9+
declare module 'express' {
10+
interface Request {
11+
user?: User;
1312
}
1413
}

backend/src/user/user.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class UserController {
1010
getProfile(@GetUser() user: User) {
1111
return {
1212
message: 'Authentication successful',
13-
user
13+
user,
1414
};
1515
}
1616
}

0 commit comments

Comments
 (0)