Javascript 对端点的权限

Javascript 对端点的权限,javascript,typescript,express,nestjs,Javascript,Typescript,Express,Nestjs,我创建自定义装饰器,以便在nest应用程序中的每个控制器上进行身份验证,如下所示: export function AuthRequired(exposeOptions?: ExposeOptions): (arg0: Controller, arg1: string, arg3: TypedPropertyDescriptor<unknown>) => void { const exposeFn = Expose(exposeOptions); const apiBe

我创建自定义装饰器,以便在nest应用程序中的每个控制器上进行身份验证,如下所示:

export function AuthRequired(exposeOptions?: ExposeOptions): (arg0: Controller, arg1: string, arg3: TypedPropertyDescriptor<unknown>) => void {
  const exposeFn = Expose(exposeOptions);
  const apiBearerAuthFn = ApiBearerAuth();
  const guardFn = UseGuards(AuthGuard())


  return function (target: Controller, key: string, descriptor: TypedPropertyDescriptor<unknown>): void {
    apiBearerAuthFn(target, key, descriptor);
    guardFn(target, key, descriptor);
    exposeFn(target, key);
  }
}
应用模块

@Module({
  imports: [
    TypeOrmModule.forRoot({
      ///
    }),
    JwtModule.register({
      secret: 'secretKey'
    }),
    AuthModule,
    UserModule,
  ],
  controllers: [AppController, UserController, AuthController],
  providers: [AppService, UserService, AuthService],
})
export class AppModule {}
应用控制器

    @Get()
    @AuthRequired()
    async getCurrentUser() {
        console.log();
    }
我不知道出了什么问题:/

昂首阔步:

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const options = new DocumentBuilder()
    .setTitle('title')
    .setDescription('desc')
    .setVersion('0.1')
    .addServer('/api', 'Main server - current/local')
    .build();
  
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api-doc', app, document);

  app.setGlobalPrefix('api');

  
  await app.listen(3000);
}
bootstrap();
根据,您缺少
DocumentBuilder
上的安全定义。尝试添加以下内容:

const options = new DocumentBuilder()
    .setTitle('title')
    .setDescription('desc')
    .setVersion('0.1')
    .addServer('/api', 'Main server - current/local')
    .addBearerAuth() // <-- note this
    .build();
const options=new DocumentBuilder()
.setTitle(“标题”)
.setDescription('desc')
.setVersion('0.1')
.addServer('/api',主服务器-当前/本地')
.addBeareAuth()//根据,您缺少
DocumentBuilder
上的安全定义。尝试添加以下内容:

const options = new DocumentBuilder()
    .setTitle('title')
    .setDescription('desc')
    .setVersion('0.1')
    .addServer('/api', 'Main server - current/local')
    .addBearerAuth() // <-- note this
    .build();
const options=new DocumentBuilder()
.setTitle(“标题”)
.setDescription('desc')
.setVersion('0.1')
.addServer('/api',主服务器-当前/本地')

.addBearerAuth()//你能告诉我们如何使用
DocumentBuilder
初始化swagger吗?@eol:我将代码粘贴在主帖子底部,你能看一下吗?你能告诉我们如何使用
DocumentBuilder
初始化swagger吗?@eol:我将代码粘贴在主帖子底部,你能看一下吗?@OP:有反馈吗?@OP:有反馈吗?
const options = new DocumentBuilder()
    .setTitle('title')
    .setDescription('desc')
    .setVersion('0.1')
    .addServer('/api', 'Main server - current/local')
    .addBearerAuth() // <-- note this
    .build();