@mercury-labs/nest-auth
Version:
Mercury framework auth library. It supports local auth, jwt with both bearer token and cookie, basic auth.
37 lines • 1.39 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRequestCookie = exports.getRequestHeader = exports.getResponseFromContext = exports.getRequestFromContext = void 0;
const graphql_1 = require("@nestjs/graphql");
function getRequestFromContext(context) {
const contextType = context.getType();
if (contextType === 'graphql') {
const ctx = graphql_1.GqlExecutionContext.create(context);
return ctx.getContext().req;
}
return context.switchToHttp().getRequest();
}
exports.getRequestFromContext = getRequestFromContext;
function getResponseFromContext(context) {
const contextType = context.getType();
if (contextType === 'graphql') {
const ctx = graphql_1.GqlExecutionContext.create(context);
return ctx.getContext().res;
}
return context.switchToHttp().getResponse();
}
exports.getResponseFromContext = getResponseFromContext;
function getRequestHeader(request, key) {
if (request.headers) {
return key ? request.headers[key] : request.headers;
}
return undefined;
}
exports.getRequestHeader = getRequestHeader;
function getRequestCookie(request, key) {
if (request.cookies) {
return key ? request.cookies[key] : request.cookies;
}
return undefined;
}
exports.getRequestCookie = getRequestCookie;
//# sourceMappingURL=http-context.helper.js.map
;