正在学习一个项目:https://github.com/taozhi1010/nest-admin,是一个nestjs的项目,里面整合了swagger,我用swagger测试的时候把Authorize
已经配置好了,但是测试接口一直提示请重新登录
,这是为什么?我之前用别人的项目,把Authorize输进去后接口就能正常执行。
下面是在nestjs中的相关代码
const swaggerOptions = new DocumentBuilder()
.setTitle('Nest-Admin')
.setDescription('Nest-Admin 接口文档')
.setVersion('2.0.0')
.addBearerAuth(
{
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
},
'token',
)
.build();
const document = SwaggerModule.createDocument(app, swaggerOptions);
是不是因为也需要传Cookie?
我看了一下它的源码,它是使用

AuthGuard
进行的token校验,在它的源码里读取的header
参数是Authorization
,你配置Authorization
试试。AuthGuard
源码位置是在server/src/common/guards/auth.guard.ts
,你可以查看试试,打个断点调试一下。