Crud: JWT Token CRUD

Created on 12 Mar 2020  路  2Comments  路  Source: nestjsx/crud

Hello,
I don't understand how to secure my endpoint with an jwt authentifcation ?
It's possible with your crud solution ?

I am a bit lost in your documentation.

Thanks

Most helpful comment

And then, I believe you can also specify guard for specific CRUD route using:

@Crud({
  model: { type: Event },
  routes: {
    createOneBase: {
      decorators: [UseGuards(AuthGuard('jwt'))],
    },
    updateOneBase: {
      decorators: [UseGuards(AuthGuard('jwt'))],
    },
  },
})

All 2 comments

Hi @WilliamKrieg:

I use jwt authentication on my crud controllers. Jwt authentication can be implemented using NestJs guards.

To implement auhentication, you basically need to implement a Guard to get the token and validate it, and then inject that guard for the controllers that need to be authenticated.

How to implement the jwt guard can be found here (It explains how to create the guard + install necessary dependencies.)

To inject the guard on your CRUD controller:

@Crud({
  model: {
    type: Event,
  },
})
@UseGuards(
  AuthGuard('jwt'),
  // Other guards
)

I hope it helps,

And then, I believe you can also specify guard for specific CRUD route using:

@Crud({
  model: { type: Event },
  routes: {
    createOneBase: {
      decorators: [UseGuards(AuthGuard('jwt'))],
    },
    updateOneBase: {
      decorators: [UseGuards(AuthGuard('jwt'))],
    },
  },
})
Was this page helpful?
0 / 5 - 0 ratings