Open soon530 opened 2 years ago
% nest g gu guards/auth
CREATE src/guards/auth/auth.guard.spec.ts (160 bytes)
CREATE src/guards/auth/auth.guard.ts (299 bytes)
放controller擋全部,放method擋一個。
@UseGuards(AuthGuard)
@Controller('user')
export class UserController {
constructor(
private readonly userService: UserService
) {}
@UseGuards(AuthGuard)
@Post()
create(@Body() body: any) {
return this.userService.create(body);
}
@Get()
findAll() {
return this.userService.findAll();
}
剛發現,不用在module中去引入。
https://ithelp.ithome.com.tw/articles/10273757