UNPKG

react-sign-in-apple

Version:
102 lines (86 loc) 2.88 kB
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var React = require('react'); var scriptjs = _interopDefault(require('scriptjs')); // A type of promise-like that resolves synchronously and supports only one observer const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator"; const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator"; // Asynchronously call a function and send errors to recovery continuation function _catch(body, recover) { try { var result = body(); } catch(e) { return recover(e); } if (result && result.then) { return result.then(void 0, recover); } return result; } var AppleLogin = function AppleLogin(props) { scriptjs('https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js', function () { var clientId = props.clientId, scope = props.scope, redirectURI = props.redirectURI, state = props.state, nonce = props.nonce, usePopup = props.usePopup; window.AppleID.auth.init({ clientId: clientId, scope: scope, redirectURI: redirectURI, state: state, nonce: nonce, usePopup: usePopup }); }); var handleSuccess = function handleSuccess(authorization) { if (typeof props.onSuccess === 'function') { props.onSuccess(authorization); } }; var handleFailure = function handleFailure(error) { if (typeof props.onFailure === 'function') { props.onFailure(error); } }; var onClick = function onClick() { try { var _temp2 = _catch(function () { return Promise.resolve(window.AppleID.auth.signIn()).then(function (data) { handleSuccess(data); }); }, function (error) { handleFailure(error); }); return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0); } catch (e) { return Promise.reject(e); } }; if (typeof props.render === 'function') { return props.render({ onClick: onClick }); } var mode = props.mode, type = props.type, appearance = props.appearance; var _ref = appearance || {}, color = _ref.color, border = _ref.border, borderRadius = _ref.borderRadius, width = _ref.width, height = _ref.height; return React.createElement("div", { id: 'appleid-signin', "data-mode": mode, "data-type": type, "data-color": color, "data-border": border, "data-border-radius": borderRadius, "data-width": width, "data-height": height }); }; exports.AppleLogin = AppleLogin; //# sourceMappingURL=index.js.map