Skip to content

Commit

Permalink
OV-159: + static path white route
Browse files Browse the repository at this point in the history
  • Loading branch information
sofiia-trokhymchuk committed Sep 4, 2024
1 parent 9795d40 commit acd0b81
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
on:
push:
branches:
- next
- fix/OV-159-add-static-path-white-route
workflow_dispatch:

jobs:
Expand Down
6 changes: 5 additions & 1 deletion backend/src/common/constants/white-routes.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const WHITE_ROUTES = [
},
{
path: /\/v1\/documentation\/.*/,
method: 'GET',
method: HTTPMethod.GET,
},
{
path: /^(?!\/api\/v1\b).*/,
method: HTTPMethod.GET,
},
];

Expand Down
12 changes: 4 additions & 8 deletions backend/src/common/plugins/auth/auth-jwt.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { HttpCode, HttpError, HttpHeader } from 'shared';
import { userService } from '~/bundles/users/users.js';
import { tokenService } from '~/common/services/services.js';

import { SERVED_PAGE_PATH } from './constants/constants.js';
import { ErrorMessage, Hook } from './enums/enums.js';
import { type Route } from './types/types.js';
import { isRouteInWhiteList } from './utils/utils.js';
Expand All @@ -17,12 +16,6 @@ const authenticateJWT = fp<Options>((fastify, { routesWhiteList }, done) => {
fastify.decorateRequest('user', null);

fastify.addHook(Hook.PRE_HANDLER, async (request) => {
const isServedPagePath = request.routeOptions.url === SERVED_PAGE_PATH;

if (isServedPagePath) {
return;
}

if (isRouteInWhiteList(routesWhiteList, request)) {
return;
}
Expand All @@ -31,7 +24,10 @@ const authenticateJWT = fp<Options>((fastify, { routesWhiteList }, done) => {

if (!authHeader) {
throw new HttpError({
message: ErrorMessage.MISSING_TOKEN,
message:
ErrorMessage.MISSING_TOKEN +
request.url +
request.routeOptions.url,
status: HttpCode.UNAUTHORIZED,
});
}
Expand Down
1 change: 0 additions & 1 deletion backend/src/common/plugins/auth/constants/constants.ts

This file was deleted.

This file was deleted.

0 comments on commit acd0b81

Please sign in to comment.