Skip to content

Commit

Permalink
fix: dont omit signoptions in sign and signasync
Browse files Browse the repository at this point in the history
removed unused @ts-expect-error

fixes nestjs#1369
  • Loading branch information
aayushchugh committed Jul 17, 2023
1 parent a35d02d commit c4e7f4e
Show file tree
Hide file tree
Showing 3 changed files with 6,041 additions and 13 deletions.
4 changes: 1 addition & 3 deletions lib/jwt.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,14 @@ describe('JWT Service', () => {

it('should "sign" expect errors with a "payload" string with "expiresIn"', () => {
expect(() =>
// @ts-expect-error
jwtService.sign(testPayloadStr, { expiresIn: 60 })
jwtService.sign(testPayloadStr, { expiresIn: 60 } as jwt.SignOptions)
).toThrowError(
'Payload as string is not allowed with the following sign options: expiresIn'
);
});

it('should "signAsync" expect errors with a "payload" string with "notBefore"', () => {
expect(() =>
// @ts-expect-error
jwtService.signAsync(testPayloadStr, { notBefore: 60 })
).toThrowError(
'Payload as string is not allowed with the following sign options: expiresIn, notBefore'
Expand Down
12 changes: 2 additions & 10 deletions lib/jwt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ export class JwtService {
private readonly options: JwtModuleOptions = {}
) {}

sign(
payload: string,
options?: Omit<JwtSignOptions, keyof jwt.SignOptions>
): string;
sign(payload: Buffer | object, options?: JwtSignOptions): string;
sign(payload: string | Buffer | object, options?: JwtSignOptions): string;
sign(payload: string | Buffer | object, options?: JwtSignOptions): string {
const signOptions = this.mergeJwtOptions(
{ ...options },
Expand Down Expand Up @@ -51,11 +47,7 @@ export class JwtService {
}

signAsync(
payload: string,
options?: Omit<JwtSignOptions, keyof jwt.SignOptions>
): Promise<string>;
signAsync(
payload: Buffer | object,
payload: string | Buffer | object,
options?: JwtSignOptions
): Promise<string>;
signAsync(
Expand Down
Loading

0 comments on commit c4e7f4e

Please sign in to comment.