3

I'm build an auth0 implementation according to here using a combination of express-jwt and jwks-rsa.
However, an error like the below occurred and the tsc can't finish properly.

Error:(102, 5) TS2322: Type 'SecretCallbackLong | GetVerificationKey' is not assignable to type 'Secret | GetVerificationKey'.
  Type 'SecretCallbackLong' is not assignable to type 'Secret | GetVerificationKey'.
    Type 'SecretCallbackLong' is not assignable to type 'GetVerificationKey'.

My code is blow.

import {expressjwt} from "express-jwt";
import * as jwksRsa from "jwks-rsa";


const checkJwt = expressjwt({
    secret: jwksRsa.expressJwtSecret({ //<--The error occurred in here.
        cache: true,
        rateLimit: true,
        jwksRequestsPerMinute: 5,
        jwksUri: `**************************`
    }),

    audience: '*****************',
    issuer: '*******************',
    algorithms: [ 'RS256' ],
});

The type error occurred in the secret value in the options setting of expressjwt.
The code above is almost a copy of here.
So, I can't figure out the solution to this problem. This is the first time of used auth0.
Anyone who can solve this problem?

typescript: 4.7.4
express: 4.18.1
jwks-rsa: 2.1.4
express-jwt: 7.7.5

Pierogi
  • 341
  • 1
  • 3
  • 17

1 Answers1

18

You can explicitly type the secret parameter as shown here: https://github.com/auth0/express-jwt/issues/288

import jwksRsa from 'jwks-rsa';
import { expressjwt, GetVerificationKey } from 'express-jwt';


const checkJwt = expressjwt({
    secret: jwksRsa.expressJwtSecret({ //<--The error occurred in here.
        cache: true,
        rateLimit: true,
        jwksRequestsPerMinute: 5,
        jwksUri: `**************************`
    }) as GetVerificationKey,

    audience: '*****************',
    issuer: '*******************',
    algorithms: [ 'RS256' ],
});
rpure
  • 196
  • 1
  • 2