23 Nest JS How to use middleware in Nest JS and it's concept

  Рет қаралды 12,598

Amitav Roy

Amitav Roy

Күн бұрын

Пікірлер: 24
@jagajaga6908
@jagajaga6908 9 ай бұрын
Bro thank you very much, very useful tutorial!!!
@amitavroydev
@amitavroydev 9 ай бұрын
You're welcome!
@nanditanikam1202
@nanditanikam1202 Жыл бұрын
Excellent explanation
@devinicin
@devinicin 5 ай бұрын
very good content bro!
@amitavroydev
@amitavroydev 5 ай бұрын
Glad you liked it
@jiteshjoshisde3154
@jiteshjoshisde3154 Жыл бұрын
Hi sir, I want to apply middleware to specific routes only, to check the user role by using user id from the headers token i want to apply the middleware to some routes only to check the user role . how can do that ?? you registered to all the routes, how can we do ti for specific routes ??
@amitavroydev
@amitavroydev Жыл бұрын
Look at the second code example on this page: docs.nestjs.com/middleware This should solve your problem.
@kelvinmandlik7395
@kelvinmandlik7395 2 жыл бұрын
How can I access params in middleware it is coming undefiend. Header, body and query is accessible but not the path params (ex. /v1/user/:userId), userId is not accessible in middleware.
@amitavroydev
@amitavroydev Жыл бұрын
You will get them inside the request object
@GabrielLogan17
@GabrielLogan17 7 ай бұрын
In the case of the token example, wouldn't it be best to use guard ?
@amitavroydev
@amitavroydev 7 ай бұрын
Yes that also can be used.
@zeroes5237
@zeroes5237 2 жыл бұрын
thank you very very much brah!!!
@amitavroydev
@amitavroydev 2 жыл бұрын
You are welcome
@AmarjeetKumar-xr2gf
@AmarjeetKumar-xr2gf 2 жыл бұрын
How to get the user logged in value after token is validated in service module..for example if user is calling getAllRoles and validatation is successfull but in Role Module service i want to get the user logged in so that i can update the db who is changing the stuff...one way i no to use in each controller method user params but i want something like storage or i dont know which is directly accessable in any service
@amitavroydev
@amitavroydev 2 жыл бұрын
I have handled that thing in the JWT strategy. When the token is validated, we have the ability to enric the user object with whatever points you want to populate. github.com/amitavdevzone/nest-js-quiz-manager/blob/master/server/src/modules/auth/jwt.strategy.ts Check this file for reference. Should help
@syedazeemjaved
@syedazeemjaved 9 ай бұрын
Why not use a guard for it? What's the difference between middleware and guards in context of NestJS? Also to check JWT token, generally guards are used using PassportJS.
@amitavroydev
@amitavroydev 9 ай бұрын
Your question is a genuine concern that many people including me had. The framework docs also address this and i quote middleware, by its nature, is dumb. It doesn't know which handler will be executed after calling the next() function. On the other hand, Guards have access to the ExecutionContext instance, and thus know exactly what's going to be executed next
@syedazeemjaved
@syedazeemjaved 9 ай бұрын
@@amitavroydev Thankyou for the comment. So that means, a guard would have been better for this scenario, or when we need access to the execution context? I'll definitely be reading about it more.
@vibhupandey5918
@vibhupandey5918 Жыл бұрын
excellent, I don't know it has only a few likes!!
@amitavroydev
@amitavroydev Жыл бұрын
Thanks
@nikhilgoyal007
@nikhilgoyal007 10 ай бұрын
thanks!
@amitavroydev
@amitavroydev 10 ай бұрын
Welcome!
@idriskodaolu4826
@idriskodaolu4826 Жыл бұрын
please i need a full video that teaches nestjs
@amitavroydev
@amitavroydev Жыл бұрын
What I have is a series of videos
NestJs Course for Beginners - Create a REST API
3:42:09
freeCodeCamp.org
Рет қаралды 1,7 МЛН
NestJS Tutorial #7 - Middleware
25:27
Anson the Developer
Рет қаралды 16 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
Decouple your NestJS code with this technique!
11:37
Marius Espejo
Рет қаралды 42 М.
NextJs Middleware | How it Works & Real Use Cases
17:26
Hamed Bahram
Рет қаралды 26 М.
Nest.js Microservices Tutorial in 20 Minutes
17:56
Michael Guay
Рет қаралды 114 М.
Nest.js Controllers Tutorial
21:56
Dave Gray
Рет қаралды 21 М.
Effortless Protected Routes In Next.js Using Middleware
15:20
Code Ryan
Рет қаралды 26 М.
26 Nest JS Guards what are they and how to use them
11:50
Amitav Roy
Рет қаралды 10 М.
What is Middleware?
10:11
IBM Technology
Рет қаралды 112 М.
APIs for Beginners - How to use an API (Full Course / Tutorial)
3:07:07
freeCodeCamp.org
Рет қаралды 3 МЛН
Learn Nest.js from Scratch by building an API
1:09:06
Academind
Рет қаралды 548 М.