check token from authorization and extract it if needed

This commit is contained in:
Mathieu Lussier 2024-07-04 14:31:15 -04:00
parent f1e1806f2b
commit 748cc21b95
Signed by: mathieulussier
GPG Key ID: EF8AC4E6BA8BCAB3

View File

@ -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) {