soon530 / nestjs-study

來學一下nestjs吧!
0 stars 0 forks source link

Guard #32

Open soon530 opened 2 years ago

soon530 commented 2 years ago

https://ithelp.ithome.com.tw/articles/10273757

soon530 commented 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)
soon530 commented 2 years ago

放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();
    }
soon530 commented 2 years ago

剛發現,不用在module中去引入。