1 | "use strict";
|
2 | var __importStar = (this && this.__importStar) || function (mod) {
|
3 | if (mod && mod.__esModule) return mod;
|
4 | var result = {};
|
5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
6 | result["default"] = mod;
|
7 | return result;
|
8 | };
|
9 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
10 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const React = __importStar(require("react"));
|
14 | const universal_cookie_1 = __importDefault(require("universal-cookie"));
|
15 | const exenv_1 = __importDefault(require("exenv"));
|
16 | const MEDIUM_USER_ID = require('../config/driver').keyMediumId;
|
17 | exports.isLoggedIn = () => {
|
18 | const val = new universal_cookie_1.default().get(MEDIUM_USER_ID);
|
19 |
|
20 | return val !== undefined;
|
21 | };
|
22 | const attach_request_1 = require("../../src/shared/components/attach-request");
|
23 |
|
24 |
|
25 | const LoggedInContext = React.createContext(undefined);
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | class ForceLogin extends React.Component {
|
38 | |
39 |
|
40 |
|
41 |
|
42 | componentDidMount() {
|
43 | if (!exports.isLoggedIn()) {
|
44 | window.location.reload();
|
45 | }
|
46 | }
|
47 | render() {
|
48 |
|
49 | return React.createElement(LoggedInContext.Provider, { value: exenv_1.default.canUseDOM ?
|
50 | new universal_cookie_1.default().get(MEDIUM_USER_ID) :
|
51 | new universal_cookie_1.default(this.props.request.headers.cookie).get(MEDIUM_USER_ID) }, this.props.children);
|
52 | }
|
53 | }
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | function withUserId(Component) {
|
60 | return function WrapperComponent(props) {
|
61 | return (React.createElement(LoggedInContext.Consumer, null, value => React.createElement(Component, Object.assign({}, props, { userId: value }))));
|
62 | };
|
63 | }
|
64 | exports.withUserId = withUserId;
|
65 | exports.default = attach_request_1.withRequest(ForceLogin);
|
66 |
|
\ | No newline at end of file |