UNPKG

react-google-oauth

Version:
183 lines (142 loc) 7 kB
webpackHotUpdatereact_google_oauth(0,{ /***/ "./src/services/index.jsx": /*!********************************!*\ !*** ./src/services/index.jsx ***! \********************************/ /*! no static exports found */ /*! all exports used */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = __webpack_require__(/*! react */ "./node_modules/react/react.js"); var _react2 = _interopRequireDefault(_react); var _propTypes = __webpack_require__(/*! prop-types */ "./node_modules/prop-types/index.js"); var _propTypes2 = _interopRequireDefault(_propTypes); var _invariant = __webpack_require__(/*! invariant */ "./node_modules/invariant/browser.js"); var _invariant2 = _interopRequireDefault(_invariant); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var insertGoogleScript = function insertGoogleScript(documentRoot, id, handleClientLoad) { //Check if script already present if (!documentRoot.getElementById(id)) { var firstScriptTag = documentRoot.getElementsByTagName('script')[0]; var scriptTag = documentRoot.createElement('script'); scriptTag.async = 'async'; scriptTag.defer = 'defer'; scriptTag.id = id; scriptTag.src = '//apis.google.com/js/client:platform.js'; scriptTag.onload = handleClientLoad; firstScriptTag.parentNode.insertBefore(scriptTag, firstScriptTag); } }; // Loads auth2 library var handleClientLoad = function handleClientLoad(initGoogleClient) { return function () { return window.gapi.load('auth2', initGoogleClient); }; }; var initGoogleClientAPI = function initGoogleClientAPI(params, onUpdateSigninStatus, onInitFailure) { return function () { var auth2 = window.gapi.auth2; auth2.init(params).then(function () { // Listen for sign-in state changes. auth2.getAuthInstance().isSignedIn.listen(onUpdateSigninStatus); // Handle the initial sign-in state. onUpdateSigninStatus(auth2.getAuthInstance().isSignedIn.get()); }, onInitFailure); }; }; var makeGoogleParams = function makeGoogleParams(props) { var clientId = props.clientId, cookiePolicy = props.cookiePolicy, hostedDomain = props.hostedDomain, fetchBasicProfile = props.fetchBasicProfile, redirectUri = props.redirectUri, uxMode = props.uxMode, scope = props.scope; return { client_id: clientId, cookiepolicy: cookiePolicy, hosted_domain: hostedDomain, fetch_basic_profile: fetchBasicProfile, ux_mode: uxMode, redirect_uri: redirectUri, scope: scope }; }; //The function called if the Google libraries failed to load. var initGoogleClientAPIFailure = function initGoogleClientAPIFailure(err) { return console.error(err); }; var GoogleAPI = function (_Component) { _inherits(GoogleAPI, _Component); function GoogleAPI() { _classCallCheck(this, GoogleAPI); return _possibleConstructorReturn(this, (GoogleAPI.__proto__ || Object.getPrototypeOf(GoogleAPI)).apply(this, arguments)); } _createClass(GoogleAPI, [{ key: 'getChildContext', value: function getChildContext() { return { reactGoogleApi: true }; } }, { key: 'componentWillMount', value: function componentWillMount() { var children = this.props.children; (0, _invariant2.default)(children == null || _react2.default.Children.count(children) === 1, 'A <GoogleAPI> may have only one child element'); } }, { key: 'componentDidMount', value: function componentDidMount() { var onUpdateSigninStatus = this.props.onUpdateSigninStatus ? this.props.onUpdateSigninStatus : function (f) { return f; }; var onInitFailure = this.props.onFailure ? this.props.onInitFailure : initGoogleClientAPIFailure; var params = makeGoogleParams(this.props); var initClient = initGoogleClientAPI(params, onUpdateSigninStatus, onInitFailure); var initGoogleApi = handleClientLoad(initClient); insertGoogleScript(document, 'react-google-oauth-id', initGoogleApi); } }, { key: 'render', value: function render() { var children = this.props.children; return children ? _react2.default.Children.only(children) : null; } }]); return GoogleAPI; }(_react.Component); GoogleAPI.childContextTypes = { reactGoogleApi: _propTypes2.default.bool }; GoogleAPI.propTypes = { onUpdateSigninStatus: _propTypes2.default.func, onInitFailure: _propTypes2.default.func, clientId: _propTypes2.default.string.isRequired, scope: _propTypes2.default.string, cookiePolicy: _propTypes2.default.string, fetchBasicProfile: _propTypes2.default.bool, prompt: _propTypes2.default.string, uxMode: _propTypes2.default.string, hostedDomain: _propTypes2.default.string, redirectUri: _propTypes2.default.string, children: _propTypes2.default.node }; GoogleAPI.defaultProps = { scope: '', cookiePolicy: 'single_host_origin', fetchBasicProfile: true, prompt: '', uxMode: 'prompt' }; exports.default = GoogleAPI; /***/ }) }) //# sourceMappingURL=0.c87d63fb2a11b74ec84e.hot-update.js.map