0

I have a NestJS controller:


@Controller('users')
@ApiTags('users')
export class UserController {
    constructor(
        private userService: UserService,
        private userRoleService: UserRoleService,
        private readonly translationService: TranslationService,
    ) {}
    @Get('organization-admin')
    @AuthorizeFor(RoleType.ORGANIZATION_ADMIN)
    @HttpCode(HttpStatus.OK)
    @ApiOkResponse({
        description: 'Access for organization admin granted'
    })
    async organizationAdmin(@AuthUser() user: UserEntity): Promise<string> {
        return `Hello organization admin ${user.firstName}`;
    }

    @Post(':id/assign-role')
    @AuthorizeFor(RoleType.ORGANIZATION_ADMIN)
    @HttpCode(HttpStatus.OK)
    @ApiOkResponse({
        status: HttpStatus.OK,
        description: 'Role assigned to user',
        type: UserRoleDto,
    })
    async assignRoleToUser(
        @Body() userRole: CreateUserRoleDto,
        @UUIDParam('id') userId: string
    ): Promise<CreateUserRoleDto> {
        const user = await this.userService.findOne({ id: userId });
        return this.userRoleService.createUserRole(user, userRole);
    }
}

Using swagger - Bearer token is attached for request @Get('organization-admin') but won't for @Post(':id/assign-role').

Could you please help me to figure out why it can happen?

Thanks in advance.

Aleksei Yerokhin
  • 869
  • 4
  • 9
  • 22

1 Answers1

0

Try add @ApiBearerAuth() decorator to your endpoints/controller