Skip to content
Merged
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
12 changes: 7 additions & 5 deletions src/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ export class AuthMiddleware implements ExpressMiddlewareInterface {
) {}

async use(request: Request, response: Response, next: (err?: any) => any): Promise<any> {
const token = request.headers.authorization?.split(' ')[1];
if (!token) {
return response.status(401).json({ message: 'You must be authenticated to call this API' });
// todo : find a better fix for this
const exemptPaths = ['/auth/login', '/auth/register', '/auth/refresh'];
const isExemptPath = exemptPaths.some((path) => request.path.startsWith(path));
if (isExemptPath) {
return next();
}

const token = request.headers.authorization?.split(' ')[1];
try {
const authData = await this.authService.getCurrentUser(token);
const authData = await this.authService.getCurrentUser(token!);
request.auth = authData;
} catch (error) {
this.logger.error(`An error occurred while validating token, ${error}`);
Expand Down
Loading