UNPKG

@slashid/docusaurus-theme-slashid

Version:
45 lines (43 loc) 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.STORAGE_KEY = void 0; exports.SlashID = SlashID; var _react = _interopRequireWildcard(require("react")); var _useIsBrowser = _interopRequireDefault(require("@docusaurus/useIsBrowser")); var _react2 = require("@slashid/react"); var _authContext = require("./auth-context"); var _slashidModule = _interopRequireDefault(require("./slashid.module.css")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /* ============================================================================ * Copyright (c) SlashID * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * ========================================================================== */ // SlashID docs depend on this const STORAGE_KEY = "MY_USER_TOKEN"; exports.STORAGE_KEY = STORAGE_KEY; function SlashID({ configuration }) { var _configuration$storeL, _configuration$defaul; const { setShowLogin } = _react.default.useContext(_authContext.AuthContext); const isBrowser = (0, _useIsBrowser.default)(); const handleSuccess = (0, _react.useCallback)(user => { setShowLogin(false); if (isBrowser) { window.localStorage.setItem(STORAGE_KEY, user.token); } }, [isBrowser, setShowLogin]); return <_react2.ConfigurationProvider factors={configuration.factors} logo={configuration.logo} storeLastHandle={(_configuration$storeL = configuration.storeLastHandle) !== null && _configuration$storeL !== void 0 ? _configuration$storeL : true} text={configuration.text} defaultCountryCode={(_configuration$defaul = configuration.defaultCountryCode) !== null && _configuration$defaul !== void 0 ? _configuration$defaul : "US"}> <main className={_slashidModule.default.slashid}> <_react2.Form className={_slashidModule.default.form} onSuccess={handleSuccess} /> </main> </_react2.ConfigurationProvider>; }