check token from authorization and extract it if needed
This commit is contained in:
parent
f1e1806f2b
commit
748cc21b95
|
@ -26,7 +26,11 @@ export const checkApiToken = async (
|
||||||
res: Response,
|
res: Response,
|
||||||
next: NextFunction
|
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 || '';
|
const secretKey = process.env.JWT_TOKEN_SECRET || '';
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user