UNPKG

react-web-native-sketch

Version:

[TODO: We need an overview of how this can be used via npm vs as a local package]

72 lines 3.13 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var react_redux_1 = require("react-redux"); var __1 = require("../"); var hoist_non_react_statics_1 = require("../lib/hoist-non-react-statics"); var navigation_1 = require("../redux/reducers/navigation"); exports.requireAuthentication = function (WrappedComponent) { var CEnhance = /** @class */ (function (_super) { __extends(CEnhance, _super); function CEnhance() { return _super !== null && _super.apply(this, arguments) || this; } CEnhance.checkRedirect = function (props) { if (!__1.isWeb) { return; } if (!navigation_1.routes.LOGIN) { console.log('Error: LOGIN route not set use "setRoutes(routes)"'); return; } var pushScreen = props.pushScreen, navigation = props.navigation, history = props.history, isLoggedIn = props.isLoggedIn; if (!isLoggedIn) { pushScreen(navigation, history, navigation_1.routes.LOGIN, null); } }; CEnhance.prototype.componentWillMount = function () { CEnhance.checkRedirect(this.props); }; CEnhance.prototype.componentWillReceiveProps = function (nextProps) { CEnhance.checkRedirect(nextProps); }; CEnhance.prototype.render = function () { var isLoggedIn = this.props.isLoggedIn; if (!__1.isWeb) { if (!isLoggedIn) { var LoginBody = navigation_1.routes.LOGIN.container; return React.createElement(LoginBody, null); } } return (React.createElement(WrappedComponent, __assign({}, this.props))); }; return CEnhance; }(React.Component)); var Enhance = react_redux_1.connect(function (state, ownProps) { return ({ isLoggedIn: __1.getNestedField(state.persisted, ['login', 'isLoggedIn']), }); }, { pushScreen: navigation_1.pushScreen, })(CEnhance); // need this for statics like react-native-navigation navigatorStyle/ navigatorButtons hoist_non_react_statics_1.hoistNonReactStatics(Enhance, WrappedComponent); return Enhance; }; //# sourceMappingURL=requireAuthentication.js.map