NestJS: JWT- and Role based API Protection | Blog Project V-04

Поделиться
HTML-код
  • Опубликовано: 26 ноя 2024

Комментарии • 59

  • @ndkebedhidwnb11
    @ndkebedhidwnb11 3 года назад +5

    Thomas!! Your Nestjs tutorial is way better than the other udemy videos. Thank you from South Korea.

  • @TommiCodes
    @TommiCodes  4 года назад +3

    Video is processing for 4k right now, should be done in the next few hours

  • @nilmendes7710
    @nilmendes7710 4 года назад +2

    This part of the tutorial was complicated.
    Thank you Professor Thomas!

  • @borys1142
    @borys1142 3 года назад

    Hi, First, this is a very good introduction tutorial to NestJS.
    One thing to highlight is that there is nothing to prevent `updateRoleOfUser` to update the entire user entity. Maybe this will be cover in the future videos, but for now looks like a duplication of `updateOne` action method.

  • @DorosBDarija
    @DorosBDarija 4 года назад

    i m happy that i found this channel, currently working on an angular/nestjs project so i think this serie of videos will be very helpfull, i'll watch them and give you my feedback, as well as if i have any question, i'll let you know, many thanks

    • @TommiCodes
      @TommiCodes  4 года назад

      Thanks! Have fun with nest and angular

  • @problemchild959
    @problemchild959 4 года назад +2

    the circular reference is actually quite easy to avoid, you don't need the entire user service in the roles guard, only the database. so instead of injecting the entire user service, use the @InjectRepository and inject just the typeorm repo then you can still do the database lookup and avoid the circular reference because all your doing is a simple lookup by id which can easily be done in the roles guard with a simple this.userRepo.findOne call. I just did it that way myself and it works perfectly and I didn't need any forwardRef and I completely avoided the circular reference issue (which really SHOULD be avoided) :)

    • @TommiCodes
      @TommiCodes  4 года назад

      Hi, yeah, should def be avoided.
      One of my next videos will fix this :)

    • @TommiCodes
      @TommiCodes  4 года назад

      I am actually thinking about implementing it as middleware.
      Cause then we are not acessing the "user" table from two modules.
      I will make a video for it. Will be published at first week in december

  • @ritwikmukhopadhyay2521
    @ritwikmukhopadhyay2521 4 года назад +1

    Hello Thomas, Thanks a lot for this tutorial, this one helped me a lot, I was looking for Role based custom guards not only just an Auth Guard, and you are an amazing teacher :-) . Waiting for your Microservices series.

    • @TommiCodes
      @TommiCodes  4 года назад +1

      Thanks. It will be coming, when this series finds an end :) Will probably take some more weeks

  • @kartikpatidar3951
    @kartikpatidar3951 4 года назад

    Please consider zooming in a little be so that mobile users can also see the code effortlessly

    • @TommiCodes
      @TommiCodes  4 года назад +1

      I can try it for the next videos. But i generally think, that coding videos should be watched on desktop. :)

    • @TommiCodes
      @TommiCodes  4 года назад +1

      I can change the config of vsc to make the code a little bit bigger

    • @problemchild959
      @problemchild959 4 года назад +1

      @@TommiCodes not everyone has multiple monitors and use their phone to play the videos while doing it on the desktop. its a royal pain (especially when people go too fast) to swap between RUclips/editor/console, etc when you only have 1 monitor/screen (I have 6 now so its not an issue but I started out with only 1 )
      :)

    • @TommiCodes
      @TommiCodes  4 года назад

      @@problemchild959 Ah thanks, didn't really thought about that.
      I adjusted the zoom for the next videos

  • @hazara-encyclopedia
    @hazara-encyclopedia 3 года назад

    When you fixed the last error and finally it ran properly, I did the same but this error appeared at the end!

  • @awmiaw8016
    @awmiaw8016 3 года назад +1

    thanks for this video, helped me a lot, even though its a little different maybe because a year has been pass..(or I just dumb haha), but I got the basic idea how it's work..

    • @TommiCodes
      @TommiCodes  3 года назад

      Should still work the same way.

  • @hazara-encyclopedia
    @hazara-encyclopedia 3 года назад

    I have a problem in this section. I don't know if I made a mistake or maybe something is updated since the video was published! (Sorry, I am new to Angular and nestjs)

  • @antonian6577
    @antonian6577 4 года назад +1

    Hi, i am looking at the nestjs doc about the validation , in nestjs doc the validation is using class-validator, do we need to change our interface to be DTO if would like to use class-validator ?

    • @TommiCodes
      @TommiCodes  4 года назад

      Hi Antoni :)
      With a DTO (Domain Transfer Object), including class-validator, we can for example validate an incoming Request, or better the Data from the incoming request. But as described here stackoverflow.com/questions/53531488/nestjs-why-do-we-need-dtos-and-interfaces-both-in-nestjs
      It normally is more needed in bigger applications.
      You can also see in the official examples, that they are using interface and dtos. For example, here they are using Interfaces github.com/nestjs/nest/tree/master/sample/01-cats-app/src/cats/interfaces
      Either way, I added it to my list, I will make a video about dtos, after i implemented the blog feature in the nestjs backend, from this playlist. Maybe i will build for the blog feature module, not just the interfaces, but also with the dto, so you can see :)
      Btw, thanks for your question :)

    • @antonian6577
      @antonian6577 4 года назад

      Thomas_Kilb thanks for the detail answer, and yes looking forward for the example of implementing about interface together with dto. thank you

    • @antonian6577
      @antonian6577 4 года назад

      Thomas_Kilb Hi, when building an apps, the most difficult part is the "state management" (cmiiw), my point is when we have to consider to combine rxjs with another state management library ? or rxjs already good enough even we are building a complex app ?

    • @TommiCodes
      @TommiCodes  4 года назад +1

      @@antonian6577 Hi, i think you are mixing some things a bit up here :)
      RXJS is not for state management, but for handling async work, for example the communication between client and server. In our nestjs backend we are already persisting the data with typeorm in our database (in this playlist here, in a postgres database).
      State management is more used on the frontend, for angular you can use ngrx (i will handle and talk about this in later videos), and is being used, to have a "single source of truth" and to store some data in the client and to synchronize the complete frontend state. So for example, if you upload a new profile image in one component, you also want your profile image (in the navbar), to change immediately.
      This could be done with writing the new link of the user profile in the ngrx store, and then ngrx will also handle the rest call to the backend.
      You can read more about actions, reducers, selectors, effects, ... and more here ngrx.io/docs
      Thanks for the question :)

  • @adamlipowski5654
    @adamlipowski5654 4 года назад

    I am sorry If I have missed something in the video, but how do you manage refreshing access tokens? I do not suppose you expect users to login every minute, right?
    (I noticed "ignore token expiration" is explicitly set to false)

    • @TommiCodes
      @TommiCodes  4 года назад

      Hi Adam, thanks for the question. You didn't miss anything. This is not included atm in this tutorial. I am planning to implement this in my next series, which is going a bit more into the details.
      - Here the token has a expiration time of 10.000 seconds. But you could also make it more. Or you can implement the refreshing, if there any questions, just ask, i will answer within time.

  • @paingsoe9392
    @paingsoe9392 4 года назад

    Really love Nest JS tutorial using observables pattern. Hope to create advance concept using nest js.

    • @TommiCodes
      @TommiCodes  4 года назад +1

      Do you have any wishes for a topic that i should cover?

    • @paingsoe9392
      @paingsoe9392 4 года назад

      @@TommiCodes image upload and hope to cover micro service as comment.

    • @TommiCodes
      @TommiCodes  4 года назад +2

      @@paingsoe9392 Image upload is on my list for July. It will cover saving it to the file system and to an aws s3 bucket.
      It will be needed, as soon as i implement the blog feature :)
      This will also start with the videos in July.
      ---- Microservice will come, when the blog series is finished.

    • @TommiCodes
      @TommiCodes  4 года назад +3

      @@paingsoe9392 Image Upload (Profile Image) is terminated for the 09 of July. So next week thursday :)
      FR
      T

    • @Vinny254
      @Vinny254 4 года назад

      @@TommiCodes Code First graphql

  • @edgararmandotrejogutierrez3375
    @edgararmandotrejogutierrez3375 3 года назад

    Awesome! Thanks! is it possible to implement role guard at controller level instead of method level? Greetings from Mexico!

    • @awmiaw8016
      @awmiaw8016 3 года назад +1

      you can add @UseGuards right after @Controller and then use @Roles on the route handler.

  • @udeepshrestha8179
    @udeepshrestha8179 4 года назад

    which shortcut/plugin are you using for auto import in vscode? btw thank you for awesome videos.

  • @simon_smale
    @simon_smale 4 года назад

    In roles.guard.ts line 29-36, why didn’t you just return roles.indexof(user.role) > 1? The extra code doesn’t seem to add much but adds a lot of visual noise and makes it harder to understand

    • @TommiCodes
      @TommiCodes  4 года назад +1

      Hi, yeah that would be possible.
      I will change this in the Next Series. There is another one coming, where I refactor and enhance this blog project.

    • @simon_smale
      @simon_smale 4 года назад

      Thomas Oliver this is a great series so far. Looking forward to the rest and next. Have you done anything with NX monorepos?

    • @TommiCodes
      @TommiCodes  4 года назад +1

      @@simon_smale Actually yes :) Have done something there on the last weekends. But atm i have no recorded videos for this. I will put it on my list :)

  • @hazara-encyclopedia
    @hazara-encyclopedia 3 года назад

    now I get this error on every request:
    {
    "statusCode": 404,
    "message": "Cannot POST /users/login",
    "error": "Not Found"
    }

  • @pathakvivek7865
    @pathakvivek7865 4 года назад

    user object is empty while console logging at 26:23.Can you please help me with that?

    • @TommiCodes
      @TommiCodes  4 года назад

      Hi, can you please upload your repo somewhere and link it, or give me a bit more context. :)
      Then I can have a look in it.
      Some questions you can already check:
      - Are you attaching the user correctly?
      - Is the user in the database, so you can find him?
      - Are you extracting the request/context correctly?

    • @prithidevghosh3161
      @prithidevghosh3161 Год назад

      hi vivek , was this problem solved?

  • @taherr1341
    @taherr1341 3 года назад

    Thank you. It is great.

  • @tranhung4010
    @tranhung4010 4 года назад

    Do you have your own blog write about whole this nestjs tutorial. I want to read to undersatand more than what you are saying in this video.Because I don't hear English well.

    • @TommiCodes
      @TommiCodes  4 года назад

      At the moment not.
      But actually, i am planning to deploy the whole project when it's finished and then maybe start blogging with it.

    • @TommiCodes
      @TommiCodes  4 года назад

      If you have questions to anything, just write it here in the comments, i try to answer everything

  • @syrinejamel8511
    @syrinejamel8511 3 года назад

    Thank youuu

  • @ameenzo
    @ameenzo 4 года назад +1

    cats