Skip to content

Commit 0a2e09b

Browse files
chore: update deps
1 parent 732daf5 commit 0a2e09b

4 files changed

Lines changed: 2027 additions & 3186 deletions

File tree

lib/jwt.service.spec.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { Test } from '@nestjs/testing';
12
import {
23
createPrivateKey,
34
createPublicKey,
45
createSecretKey,
56
generateKeyPairSync,
67
KeyObject
78
} from 'crypto';
8-
import { Test } from '@nestjs/testing';
99
import * as jwt from 'jsonwebtoken';
1010
import {
1111
JwtModuleOptions,
@@ -306,10 +306,7 @@ describe('JwtService', () => {
306306
const testPayload: string = getRandomString();
307307

308308
beforeAll(async () => {
309-
jwtService = await setup({
310-
...config,
311-
secretOrKeyProvider: undefined
312-
});
309+
jwtService = await setup({ ...config, secretOrKeyProvider: undefined });
313310
});
314311

315312
const secret = 'custom_secret';
@@ -401,9 +398,7 @@ describe('JwtService', () => {
401398
});
402399

403400
describe('should use invalid sign options', () => {
404-
const signOptions: jwt.SignOptions = {
405-
expiresIn: '1d'
406-
};
401+
const signOptions: jwt.SignOptions = { expiresIn: '1d' };
407402

408403
let jwtService: JwtService;
409404
const testPayloadStr: string = getRandomString();
@@ -417,7 +412,7 @@ describe('JwtService', () => {
417412
expect(() =>
418413
// @ts-expect-error
419414
jwtService.sign(testPayloadStr, { expiresIn: 60 })
420-
).toThrowError(
415+
).toThrow(
421416
'Payload as string is not allowed with the following sign options: expiresIn'
422417
);
423418
});
@@ -426,7 +421,7 @@ describe('JwtService', () => {
426421
expect(() =>
427422
// @ts-expect-error
428423
jwtService.signAsync(testPayloadStr, { notBefore: 60 })
429-
).toThrowError(
424+
).toThrow(
430425
'Payload as string is not allowed with the following sign options: expiresIn, notBefore'
431426
);
432427
});
@@ -442,13 +437,13 @@ describe('JwtService', () => {
442437
});
443438

444439
it('should "sign" expect errors using "payload" string with already defined invalid sign options', () => {
445-
expect(() => jwtService.sign(testPayloadStr)).toThrowError(
440+
expect(() => jwtService.sign(testPayloadStr)).toThrow(
446441
'Payload as string is not allowed with the following sign options: expiresIn'
447442
);
448443
});
449444

450445
it('should "signAsync" expect errors using "payload" string with already defined invalid sign options', () => {
451-
expect(() => jwtService.signAsync(testPayloadStr)).toThrowError(
446+
expect(() => jwtService.signAsync(testPayloadStr)).toThrow(
452447
'Payload as string is not allowed with the following sign options: expiresIn'
453448
);
454449
});

lib/jwt.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class JwtService {
128128
throw new WrongSecretProviderError();
129129
}
130130

131-
return jwt.verify(token, secret, verifyOptions) as T;
131+
return jwt.verify(token, secret, verifyOptions as jwt.VerifyOptions) as T;
132132
}
133133

134134
verifyAsync<T extends object = any>(
@@ -147,8 +147,11 @@ export class JwtService {
147147
Promise.resolve()
148148
.then(() => secret)
149149
.then((scrt: GetSecretKeyResult) => {
150-
jwt.verify(token, scrt, verifyOptions, (err, decoded) =>
151-
err ? reject(err) : resolve(decoded as T)
150+
jwt.verify(
151+
token,
152+
scrt,
153+
verifyOptions as jwt.VerifyOptions,
154+
(err, decoded) => (err ? reject(err) : resolve(decoded as T))
152155
);
153156
})
154157
.catch(reject)
@@ -170,10 +173,7 @@ export class JwtService {
170173
delete (options as JwtVerifyOptions).publicKey;
171174
}
172175
return options
173-
? {
174-
...(this.options[key] || {}),
175-
...options
176-
}
176+
? ({ ...(this.options[key] || {}), ...options } as jwt.VerifyOptions)
177177
: this.options[key];
178178
}
179179

0 commit comments

Comments
 (0)