Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bearer authorization on swagger ui #107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,26 @@ export const setupApp = () => {
swagger({
documentation: {
info: { title, version, description },
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
description: 'Bearer token to access these api endpoints',
scheme: 'bearer',
bearerFormat: 'JWT',
},
},
},
security: [
{
bearerAuth: [],
},
],
},
exclude: ['/'],
swaggerOptions: {
persistAuthorization: true,
},
}),
)
.group('/api', (app) => app.use(usersPlugin).use(profilesPlugin));
Expand Down
6 changes: 3 additions & 3 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as jose from 'jose';
import { env } from '@config';
import { UserInDb } from '@users/users.schema';
import type { UserInDb } from '@users/users.schema';
import { Type } from '@sinclair/typebox';
import { Value } from '@sinclair/typebox/value';
import { AuthenticationError } from '@errors';
Expand Down Expand Up @@ -69,9 +69,9 @@ export class AuthService {

const tokenParts = rawHeader?.split(' ');
const tokenType = tokenParts?.[0];
if (tokenType !== 'Token')
if (tokenType !== 'Bearer')
throw new AuthenticationError(
"Invalid token type. Expected header format: 'Token jwt'",
"Invalid token type. Expected header format: 'Bearer jwt'",
);

const token = tokenParts?.[1];
Expand Down