@@ -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 }
0 commit comments