diff --git a/src/middlewares/auth.middleware.ts b/src/middlewares/auth.middleware.ts index 6eff4e5..0c7020a 100644 --- a/src/middlewares/auth.middleware.ts +++ b/src/middlewares/auth.middleware.ts @@ -26,7 +26,11 @@ export const checkApiToken = async ( res: Response, next: NextFunction ) => { - const token = req.headers['x-api-key']; + let token = req.headers['x-api-key'] || req.headers['authorization']; + // if token is in the authorization header, we need to extract it + if (token && token.toString().startsWith('Bearer ')) { + token = token.toString().replace('Bearer ', ''); + } const secretKey = process.env.JWT_TOKEN_SECRET || ''; if (!token) {