UNPKG

@krowdy/kds-auth

Version:

React components that implement Google's Material Design.

65 lines (59 loc) 1.96 kB
/* global google */ import React, { useEffect } from 'react'; import { makeStyles } from '@krowdy/kds-core'; import { useAuth } from '../utils'; var GoogleLogin = function GoogleLogin(_ref) { var isLoaded = _ref.isLoaded; var classes = useStyles(); var _ref2 = useAuth() || {}, onUpdateState = _ref2.onUpdateState, validateSocialNetwork = _ref2.validateSocialNetwork, _ref2$googleCredentia = _ref2.googleCredentials; _ref2$googleCredentia = _ref2$googleCredentia === void 0 ? {} : _ref2$googleCredentia; var clientId = _ref2$googleCredentia.clientId; var _handleResponseGoogle = function _handleResponseGoogle(response) { var tokenId = response.credential; validateSocialNetwork('google', { tokenId: tokenId }); }; useEffect(function () { if (isLoaded) try { google.accounts.id.initialize({ auto_select: true, callback: _handleResponseGoogle, cancel_on_tap_outside: true, client_id: clientId, prompt_parent_id: 'googleContainer' }); google.accounts.id.prompt(function (notification) { if (notification.isDisplayed()) onUpdateState({ oneTapGoogleDisplay: true });else if (notification.getSkippedReason() === 'user_cancel' || notification.getNotDisplayedReason()) onUpdateState({ oneTapGoogleDisplay: false }); }); } catch (error) { // eslint-disable-next-line no-console console.log(error); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [isLoaded]); return /*#__PURE__*/React.createElement("div", { className: classes.googleContainer, id: "googleContainer" }); }; var useStyles = makeStyles(function (_ref3) { var zIndex = _ref3.zIndex; return { googleContainer: { position: 'fixed', right: 20, top: 20, zIndex: zIndex.modal + 1 } }; }, { name: 'GoogleLogin' }); export default React.memo(GoogleLogin);