UNPKG

react-web-native-sketch

Version:

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

68 lines 2.44 kB
"use strict"; /** * Created by alexbuicescu on 21 - Mar 2018. */ Object.defineProperty(exports, "__esModule", { value: true }); function googleComponentDidMount(props) { var autoLoad = props.autoLoad, loadedGoogleSdk = props.loadedGoogleSdk, scope = 'profile email'; // scope = 'profile email ' + ( // params.required_user_fields.indexOf(REQUIRED_USER_FIELDS.google_calendar) !== -1 // ? 'https://www.googleapis.com/auth/calendar' : // '' // ); var fjs = document.getElementsByTagName('script')[0]; var js = document.createElement('script'); js.id = 'google-login'; js.src = '//apis.google.com/js/client:platform.js'; if (fjs.parentNode) { fjs.parentNode.insertBefore(js, fjs); } js.onload = function () { window.gapi.load('auth2', function () { loadedGoogleSdk(); if (!window.gapi.auth2.getAuthInstance()) { window.gapi.auth2.init({ client_id: '123', // cookiepolicy: cookiePolicy, // login_hint: loginHint, // hosted_domain: hostedDomain, scope: scope, }); } if (autoLoad) { googleOnClick(props); } }); }; } exports.googleComponentDidMount = googleComponentDidMount; function googleOnClick(props) { if (props.googleSdkIsLoaded) { var auth2 = window.gapi.auth2.getAuthInstance(); var redirectUri = props.redirectUri, approvalPrompt = props.approvalPrompt; var options = { redirect_uri: redirectUri, approval_prompt: approvalPrompt, }; auth2.grantOfflineAccess(options) .then(function (res) { googleSignInSuccessCallback(props, res); }, function (err) { googleSignInFailCallback(props, err); }); } } exports.googleOnClick = googleOnClick; function googleSignInSuccessCallback(props, response) { if (response.code === null) { return; } var socialLogin = props.socialLogin, referralCode = props.referralCode; socialLogin('url-here', 'post', 'google', response.code, response.code, referralCode || null, null); } function googleSignInFailCallback(props, response) { } function googleSignOut() { } exports.googleSignOut = googleSignOut; //# sourceMappingURL=googleLoginUtils.js.map