多 Guard 使用
@UseGuards(AuthGuard, PermissionGuard)
export class UserController {}
@UseGuards(AuthGuard)
@UseGuards(PermissionGuard)
export class UserController {}
在前一个 authGuard 注入request[‘user’] 信息,在permissionGuard 死活拿不到,原来要用第一个写法;
RouterModule
目前只支持一级目录嵌套,不支持二级以上 。我原本对项目结构的设想是:appModule > adminModule > authModule ,然后我在 appModule 中做了 adminModule 的路由注册,发现不管用,那只能去下一级 adminModule 中去定义或者直接在Controller 装饰器定义
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AdminModule } from './admin/admin.module';
import { RouterModule } from '@nestjs/core';
import { ClientModule } from './client/client.module';
@Module({
imports: [
ClientModule,
AdminModule,
RouterModule.register([
{
path: 'admin',
module: AdminModule,
},
{
path: 'client',
module: ClientModule,
},
]),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
import { Controller, Post, Req, UseGuards } from '@nestjs/common';
import { AuthService } from './auth.service';
import { LocalAuthGuard } from './local-auth.guard';
@Controller('admin/auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Post('signin')
@UseGuards(LocalAuthGuard)
signIn(@Req() req) {
return req.user;
}
}