UNPKG

infrastructure-components

Version:

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

45 lines 1.83 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; }; Object.defineProperty(exports, "__esModule", { value: true }); const React = __importStar(require("react")); /** * implements [[RequireServerRenderingSpec]] * * the ForceLogin Component is a HOC that passes the userid to its child components * the forceLogin gets the cookie value regardless on whether it runs on the server or in the browser * see: https://www.npmjs.com/package/universal-cookie * * see hocs with context: https://itnext.io/combining-hocs-with-the-new-reacts-context-api-9d3617dccf0b * * how to check whether running on server or in browser: https://www.npmjs.com/package/exenv */ class ForceLogin extends React.Component { /** * When we run in the browser: if not logged in, then make the page reload from the server to * make the login-middlewares apply */ componentDidMount() { //console.log("ForceLogin-Component: ", this.props.identityKey) if (this.props.userId == undefined) { window.location.reload(); } } render() { //console.log("ForceLogin: request ->", this.props.request) // we provide the information which user is logged in return React.createElement("div", null, this.props.children); } } const attach_user_1 = require("./attach-user"); /** * we MUST NOT IMPORT CONTEXTs directly, but require them at time of use generally from Infrastructure-Components * because this then resolves to node_modules */ exports.default = attach_user_1.withUser(ForceLogin); //# sourceMappingURL=force-login.js.map