Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
],
"security": [
{
"AccessToken": []
"bearer": []
}
]
}
Expand Down Expand Up @@ -113,7 +113,7 @@
],
"security": [
{
"AccessToken": []
"bearer": []
}
]
}
Expand Down Expand Up @@ -151,7 +151,7 @@
],
"security": [
{
"AccessToken": []
"bearer": []
}
]
}
Expand Down Expand Up @@ -189,7 +189,7 @@
],
"security": [
{
"AccessToken": []
"bearer": []
}
]
}
Expand All @@ -205,10 +205,10 @@
"servers": [],
"components": {
"securitySchemes": {
"AccessToken": {
"type": "apiKey",
"in": "header",
"name": "x-access-token"
"bearer": {
"scheme": "bearer",
"bearerFormat": "JWT",
"type": "http"
}
},
"schemas": {
Expand Down
8 changes: 4 additions & 4 deletions src/api/controllers/packs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JwtAuthGuard } from '../guards/jwt-auth.guard';
import { User } from '../decorators/user.decorator';
import { UserEntity, UserModel } from 'src/infra/postgres/entities/user.entity';
import { PacksUseCase } from 'src/core/use-cases/packs.use-case';
import { ApiCreatedResponse, ApiNotFoundResponse, ApiOkResponse, ApiSecurity, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiCreatedResponse, ApiNotFoundResponse, ApiOkResponse, ApiSecurity, ApiTags } from '@nestjs/swagger';
import { UUIDv4 } from 'src/common/types';
import { Mapper } from '@automapper/core';
import { PackEntity } from 'src/infra/postgres/entities/pack.entity';
Expand All @@ -28,7 +28,7 @@ export class PacksController {
) {}

@ApiOkResponse({ type: [PackOutputDTO] })
@ApiSecurity('AccessToken')
@ApiBearerAuth()
@Get()
@UseGuards(JwtAuthGuard)
public async getPacks(): Promise<Array<PackOutputDTO>> {
Expand All @@ -39,7 +39,7 @@ export class PacksController {

@ApiOkResponse({ type: PackWithPokemonsOutputDTO })
@ApiNotFoundResponse()
@ApiSecurity('AccessToken')
@ApiBearerAuth()
@Get(':id')
@UseGuards(JwtAuthGuard)
public async getPack(
Expand All @@ -54,7 +54,7 @@ export class PacksController {
// TODO: openPack should return OpenedPackEntity ({ openedAt: Date, user: UserEntity, pack: PackEntity, pokemon: PokemonEntity })
@ApiCreatedResponse({ type: OpenPackOutputDTO })
@ApiNotFoundResponse()
@ApiSecurity('AccessToken')
@ApiBearerAuth()
@Post(':id/open')
@UseGuards(JwtAuthGuard)
public async openPack(
Expand Down
4 changes: 2 additions & 2 deletions src/api/controllers/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UsersUseCase } from 'src/core/use-cases/users.use-case';
import { JwtAuthGuard } from '../guards/jwt-auth.guard';
import { UserEntity, UserModel } from 'src/infra/postgres/entities/user.entity';
import { User } from '../decorators/user.decorator';
import { ApiOkResponse, ApiSecurity, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { Mapper } from '@automapper/core';
import { InjectMapper } from '@automapper/nestjs';
import { UserWithPokemonsOutputDTO } from '../dtos/users/user-with-pokemons.output.dto';
Expand All @@ -19,7 +19,7 @@ export class UsersController {
) {}

@ApiOkResponse({ type: UserWithPokemonsOutputDTO })
@ApiSecurity('AccessToken')
@ApiBearerAuth()
@Get('me')
@UseGuards(JwtAuthGuard)
public async getMe(@User() user: UserModel) {
Expand Down
4 changes: 1 addition & 3 deletions src/api/strategies/jwt-auth.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export class JwtAuthStrategy extends PassportStrategy(Strategy) {
configService: ConfigService<EnvVariables>,
) {
super({
jwtFromRequest: ExtractJwt.fromExtractors([
ExtractJwt.fromHeader('x-access-token'),
]),
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: configService.getOrThrow('JWT_SECRET'),
});
Expand Down
6 changes: 1 addition & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ const PUBLIC_PATH = './public';
function initializeSwaggerDocumentation(app: INestApplication) {
const swaggerDocs = new DocumentBuilder()
.setTitle('Poketrade API')
.addSecurity('AccessToken', {
type: 'apiKey',
in: 'header',
name: 'x-access-token',
})
.addBearerAuth()
.build();

const document = SwaggerModule.createDocument(app, swaggerDocs);
Expand Down