UNPKG

auth0-lock

Version:
94 lines (91 loc) 4.63 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.syncRemoteData = syncRemoteData; var _immutable = _interopRequireDefault(require("immutable")); var _settings = require("./client/settings"); var _settings2 = require("./tenant/settings"); var _data = require("./sso/data"); var l = _interopRequireWildcard(require("./index")); var _enterprise = require("../connection/enterprise"); var _sync = _interopRequireWildcard(require("../sync")); var _web_api = _interopRequireDefault(require("./web_api")); var _index2 = require("../core/index"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } // shouldn't depend on this function syncRemoteData(m) { var initialScreen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'login'; if (l.useTenantInfo(m)) { m = (0, _sync.default)(m, 'client', { syncFn: function syncFn(m, cb) { return (0, _settings2.fetchTenantSettings)(l.tenantBaseUrl(m), cb); }, successFn: function successFn(m, result) { return (0, _settings2.syncTenantSettingsSuccess)(m, l.clientID(m), result); } }); } else { m = (0, _sync.default)(m, 'client', { syncFn: function syncFn(m, cb) { return (0, _settings.fetchClientSettings)(l.clientID(m), l.clientBaseUrl(m), cb); }, successFn: _settings.syncClientSettingsSuccess }); } m = (0, _sync.default)(m, 'sso', { conditionFn: function conditionFn(m) { return l.auth.sso(m) && l.ui.rememberLastLogin(m); }, waitFn: function waitFn(m) { return (0, _sync.isSuccess)(m, 'client'); }, syncFn: function syncFn(m, cb) { (0, _data.fetchSSOData)(l.id(m), (0, _enterprise.isADEnabled)(m), function () { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } l.emitEvent(m, 'ssodata fetched', args); cb.apply(void 0, args); }); }, successFn: function successFn(m, result) { return m.mergeIn(['sso'], _immutable.default.fromJS(result)); }, errorFn: function errorFn(m, error) { if (error.error === 'consent_required') { l.warn(m, error.error_description); } else { // location.origin is not supported in all browsers var origin = location.protocol + '//' + location.hostname; if (location.port) { origin += ':' + location.port; } var appSettingsUrl = "https://manage.auth0.com/#/applications/".concat(l.clientID(m), "/settings"); l.warn(m, "There was an error fetching the SSO data. This is expected - and not a problem - if the tenant has Seamless SSO enabled. If the tenant doesn't have Seamless SSO enabled, this could simply mean that there was a problem with the network. But, if a \"Origin\" error has been logged before this warning, please add \"".concat(origin, "\" to the \"Allowed Web Origins\" list in the Auth0 dashboard: ").concat(appSettingsUrl)); } } }); if (initialScreen === 'login') { m = (0, _sync.default)(m, 'captcha', { syncFn: function syncFn(m, cb) { _web_api.default.getChallenge(m.get('id'), function (err, r) { cb(null, r); }); }, successFn: _index2.setCaptcha }); } else if (initialScreen === 'signUp') { m = (0, _sync.default)(m, 'signupCaptcha', { syncFn: function syncFn(m, cb) { _web_api.default.getSignupChallenge(m.get('id'), function (err, r) { cb(null, r); }); }, successFn: _index2.setSignupChallenge }); } return m; }