Skip to content

Commit

Permalink
BACKEND-11: Fix auth issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnie4k committed Sep 12, 2024
1 parent 8c0ee18 commit d9042b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { authMiddleware } from "./middleware/authMiddleware";
const app = express();
app.use(bodyParser.json());

// Define auth middleware first
app.use(authMiddleware);

// Default Route
app.get("/", (req, res) => {
return res.sendFile("index.html", { root: __dirname });
Expand All @@ -24,6 +21,10 @@ app.use("/api-docs", swaggerUI.serve, async (req: Request, res: Response) => {
swaggerUI.generateHTML(await import("../build/swagger.json"))
);
});

// Define auth middleware first
app.use(authMiddleware);

RegisterRoutes(app);

// Define error middleware last
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const authMiddleware = async (
res: Response,
next: NextFunction
): Promise<Response | void> => {
// Exclude getActiveAnnouncements route
// Exclude getActiveAnnouncements and API docs route
const routePattern = /^\/announcements\/\w+/;
if (routePattern.test(req.path)) {
return next();
Expand Down

0 comments on commit d9042b1

Please sign in to comment.