Oh, I see. Please check the tutorial again. If you followed to the end, you will realized that the blogModule was later updated and an explanation provided for it. This is what it looks like towards the end of the tutorial:
-----blog.module.ts:
import { Module } from â@nestjs /commonâ;
import { BlogService } from â./blog.serviceâ;
import { BlogController } from â./blog.controllerâ;
import { MongooseModule } from â@nestjs /mongooseâ; // add this
import { BlogSchema } from â./schemas/blog.schemaâ; // and this
@Module ({
imports: [
MongooseModule.forFeature([{ name: âPostâ, schema: BlogSchema }]),
], // add
providers: [BlogService],
controllers: [BlogController]
})
export class BlogModule {}
2 Likes
Thanks for providing the explanation @yemiwebby !
1 Like
thank you very much, I will check, lets see what happen
2 Likes
For those that get the error âError: algorithms should be setâ from express-jwt, the following will be useful:
It seems that the latest version of express-jwt does not like RS256.
2 Likes
Thanks for sharing that with the rest of community @shafique.jamal !
Skezey
October 20, 2020, 6:49pm
17
The issue is that the guide lists the algorithm as algorithm: ['RS256']
, when it should be algorithms: ['RS256'],
I was able to get it to work by adding the s to the end of algorithms
3 Likes
Glad you have it working and thanks for sharing with the rest of community!
I was actually here for this, for the solution @Skezey
Can it be corrected in the tutorial @yemiwebby ?
2 Likes
I contacted our content team regarding that.
1 Like
Howdy! I apologize for the late reply. Weâll fix this on the live post
1 Like
Thanks @Skezey !! that comment was just what I needed to solve the issue
1 Like
Woooohooo teamwork makes the dreamwork!
Hi! thanks for this post, It really help me out! I have only one concern: Using this middleware, Are the claims inside the token validated?
This topic was automatically closed 26 days after the last reply. New replies are no longer allowed.
Hi, Iâve run the command npm install express-jwt jwks-rsa dotenv and copied the authentication.middleware.ts exactly from the post. But I see the error-
src/common/authentication.middleware.ts:11:5 - error TS2349: This expression is not callable.
Type 'typeof import("D:/nestJS/blog-backend/node_modules/express-jwt/dist/index")' has no call signatures.
11 jwt({
My resource versions:
"dotenv": "^16.0.1",
"express-jwt": "^7.7.5",
"jwks-rsa": "^2.1.4",
Iâve applied multiple solutions for StackOverFlow and tried jwt-express official website . But no solution yet.
How can I solve it?
Your version of express-jwt is newer than that used in the article. Try installing âexpress-jwtâ: â^6.0.0â and see if that works.
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();
});
}
}`
Is there a guide similar to this on how to get the role assigned to a user?