"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_1 = __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
 */
const ForceLogin = (props) => {
    /**
     * When we run in the browser: if not logged in, then make the page reload from the server to
     * make the login-middlewares apply
     */
    react_1.useEffect(() => {
        //console.log("ForceLogin-Component: ", this.props.identityKey)
        if (props.userId == undefined) {
            window.location.reload();
        }
    });
    //console.log("ForceLogin: request ->", this.props.request)
    // we provide the information which user is logged in
    return react_1.default.createElement(react_1.default.Fragment, null, 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