NestJS Interceptors

Sdílet
Vložit
  • čas přidán 21. 12. 2023
  • Support the Channel:
    Become a Member: czcams.com/users/ansonthedevel...
    Become a Patreon: / stuyy
    Buy me a Coffee: ko-fi.com/anson
    Donate on Streamlabs: streamlabs.com/ansondevacadem...
    Donate on PayPal: paypal.me/ansonfoong
    Connect with me:
    Twitter: / ansonthedev
    Discord: / discord
    GitHub: github.com/stuyy
    Twitch: / stuy
  • Jak na to + styl

Komentáře • 14

  • @allessms
    @allessms Před 6 měsíci +1

    thank you Anson! it's a clear explanation!

  • @mustafa-ahmed-dev
    @mustafa-ahmed-dev Před 27 dny

    Amazing explanation, keep up the good work
    Thank you

  • @malamhari_
    @malamhari_ Před měsícem

    It really helps me, by any means A LOT.
    Thank you sir

  • @glebbondarenko67
    @glebbondarenko67 Před 25 dny

    Cool videos about NestJS, I have no idea why you have so few subscribers

  • @bugraotken
    @bugraotken Před 7 měsíci

    Thank you Anson! Maybe you can add this video inside your Nest.js tutorials playlist?

    • @ansonthedev
      @ansonthedev  Před 7 měsíci

      It's already in the playlist. Thanks for checking.

  • @trentcox9239
    @trentcox9239 Před 6 měsíci

    loving your channel mate! is there any way you can get around to showing how to implement auth between a nextjs app and a nestjs api? its a god damn information minefield out there trying to make heads or tails of how to do it properly, at least until auth.js finally releases support for express.js...

  • @dmsnm
    @dmsnm Před 7 měsíci +1

    So would this be a good way to intercept for authentication state if implemented without an external library? Like check for validity of access token from request header/cookie?
    How is this different from express middleware?

    • @ansonthedev
      @ansonthedev  Před 7 měsíci +3

      Middleware is called first, then guards, then the interceptor. It can be a bit confusing on where things should go. Generally, it really is up to you how you want to handle where you want certain logic to happen. You can check the request header in a middleware, perform some logic, then pass it to a Guard, the guard can validate the request and grant access or reject if certain conditions are not met, then after the Guard, the Interceptor will be invoked if the Guard passes, at this point you have the implication that the user is authenticated, so you could do stuff like logging, emit an event to allow an async process occur, etc.
      Generally, I would use interceptors only if I have a need to transform the response. As there are many options to perform logic before the request hits the Route Handler in the Controller. For example, we filtered out all passwords from the Users array before we sent the response back to the client. This would allow you to separate concerns between each layer, making it MUCH easier to write Unit Tests, and helps you dig into the layer that is causing any errors, bugs, etc. while E2E testing or manual testing as a user.
      So in short: Use Interceptors if you need to transform the response back to the client. Otherwise, there are likely better options for what you are needing to do. Hope this helps.

    • @dmsnm
      @dmsnm Před 7 měsíci

      @@ansonthedev Thanks

    • @ericpeng6128
      @ericpeng6128 Před měsícem

      @@ansonthedev Thanks for the explanation! I was wondering about the necessity of using intercepter this whole video, lol.

  • @thanhduynguyen6253
    @thanhduynguyen6253 Před 6 měsíci +1

    Tks Anson, could you make video about jwt and accessToken and refreshToken with Nestjs

    • @PatalJunior
      @PatalJunior Před 6 měsíci

      Would love to see a video on it.

  • @abdelbassetchettouh7416
    @abdelbassetchettouh7416 Před měsícem

    i couldn't find the github repo
    i'm that kind of guy that understands with practice
    pls response ASAP