UNPKG

infrastructure-components

Version:

Infrastructure-Components configure the infrastructure of your React-App as part of your React-Components.

49 lines 1.96 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const React = __importStar(require("react")); const types_1 = __importDefault(require("../types")); const loader_1 = require("../libs/loader"); // create empty context as default const AuthContext = React.createContext({}); /** * This HOC attaches the auth-callback to a webapp, may be undefined! */ const AttachAuth = (props) => { //console.log("attach auth: ", props.authCallback); return React.createElement(AuthContext.Provider, { value: { authCallback: props.authCallback } }, props.children); }; /** * @param Component * @returns {function(any): any} */ function withAuthCallback(Component) { return function WrapperComponent(props) { return (React.createElement(AuthContext.Consumer, null, (context) => { return React.createElement(Component, Object.assign({}, props, { authCallback: context.authCallback })); })); }; } exports.withAuthCallback = withAuthCallback; exports.getAuthCallback = (isoConfig, authenticationId) => { const authComp = loader_1.extractObject(isoConfig, types_1.default.INFRASTRUCTURE_TYPE_COMPONENT, authenticationId); const authCallback = authComp !== undefined ? authComp.authCallback : (triggerRedirect) => { console.log("this is the dummy auth callback"); return undefined; }; //console.log("getAuthCallback: ", authCallback) return authCallback; }; exports.default = AttachAuth; //# sourceMappingURL=attach-auth.js.map