Try this
`import { Injectable, NestMiddleware } from â@nestjs/commonâ;
import { expressjwt, GetVerificationKey } from âexpress-jwtâ;
import { expressJwtSecret } from âjwks-rsaâ;
import { Request, Response } from âexpressâ;
import { ConfigService } from â@nestjs/configâ;
// require(âdotenvâ).config();
@Injectable()
export class AuthenticationMiddleware implements NestMiddleware {
constructor(private readonly configService: ConfigService) {}
use(req: Request, res: Response, next: Function) {
expressjwt({
secret: expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: https://${this.configService.get('auth_domain')}/.well-known/jwks.json
,
}) as GetVerificationKey,
issuer: https://${this.configService.get('auth_domain')}/
,
algorithms: [âRS256â],
})(req, res, (err) => {
if (err) {
const status = err.status || 500;
const message = err.message || âSorry we were unable to process your request.â;
return res.status(status).send({
message,
});
}
next();
});
}
}`