@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
29 lines (28 loc) • 1.12 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.authenticate = void 0;
const auth_api_key_1 = require("./auth-api-key");
const auth_jwt_1 = __importDefault(require("./auth-jwt"));
const authenticate = async (req, res, next) => {
// API_ACCESS_TOKEN will be transformed to lowercase in Express:
// console.log("req.headers :>> ", req.headers);
var _a;
try {
const API_ACCESS_TOKEN = (_a = req.headers["x-api-key"]) === null || _a === void 0 ? void 0 : _a.toString();
// console.log("req.headers[x-api-key] :>> ", API_ACCESS_TOKEN);
// console.log("req.headers.authorization :>> ", req.headers.authorization);
if (API_ACCESS_TOKEN) {
return await (0, auth_api_key_1.apiAccessTokenHandler)(req, res, next);
}
else {
return (0, auth_jwt_1.default)(req, res, next);
}
}
catch (e) {
next(e);
}
};
exports.authenticate = authenticate;