对不起,我是nestJs的新手,我使用的是github中的示例应用程序:
https://github.com/lujakob/nestjs-realworld-example-app
我的问题是关于如何对有权修改特定文章的用户进行正式验证。通常,这部分代码应进行验证:
@ApiOperation({ summary: 'Update article' })
@ApiResponse({ status: 201, description: 'The article has been successfully updated.'})
@ApiResponse({ status: 403, description: 'Forbidden.' })
@put(':slug')
async update(@param() params, @Body('article') articleData: CreateArticleDto) {
// Todo: update slug also when title gets changed
return this.articleService.update(params.slug, articleData);
}
以便不是每个人都可以修改其他文章。
谢谢
答案 0 :(得分:0)
NestJS具有Guards的概念 https://docs.nestjs.com/guards
Guard是另一种类型的中间件,将在调用路由处理程序之前执行。守卫只是一种机制,可以帮助您保护自己的路线。您需要实施基础实现(例如角色或权限)。