@geniucode/common-utils
Version:
Common utils
19 lines • 701 B
JavaScript
import { TErrors } from '@geniucode/terminator';
import { logi } from '../logger';
const logger = logi(__filename);
export const validateApiKey = (req, res, next) => {
const headerApiKey = req.header('api-key');
const apiToken = process.env.API_KEY;
if (!headerApiKey) {
const msg = 'core-modules-Error | Missing HTTP Headers...';
logger.error(msg);
throw new TErrors.ValidationError(msg);
}
if (headerApiKey !== apiToken) {
const msg = 'core-modules-Error | No permission, please check your header data';
logger.error(msg);
throw new TErrors.NotAuthorizedError(msg);
}
next();
};
//# sourceMappingURL=validate-api-key.js.map