Modern Full-Stack Development with Nest.js, React, TypeScript, and MongoDB: Part 1

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:

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

imports: [
MongooseModule.forFeature([{ name: ‘Post’, schema: BlogSchema }]),
], // add
providers: [BlogService],
controllers: [BlogController]
export class BlogModule {}


Thanks for providing the explanation @yemiwebby!

1 Like

thank you very much, I will check, lets see what happen


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.


Thanks for sharing that with the rest of community @shafique.jamal!

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


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 ?


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:

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 :slight_smile:

`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();

export class AuthenticationMiddleware implements NestMiddleware {
constructor(private readonly configService: ConfigService) {}
use(req: Request, res: Response, next: Function) {
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({

Is there a guide similar to this on how to get the role assigned to a user?