infinity-forge
Version:
79 lines • 5.2 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GoogleLogin = GoogleLogin;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var GoogleOAuthProvider_1 = require("./GoogleOAuthProvider.js");
var utils_1 = require("./utils/index.js");
var containerHeightMap = { large: 40, medium: 32, small: 20 };
function GoogleLogin(_a) {
var onSuccess = _a.onSuccess, onError = _a.onError, useOneTap = _a.useOneTap, promptMomentNotification = _a.promptMomentNotification, _b = _a.type, type = _b === void 0 ? 'standard' : _b, _c = _a.theme, theme = _c === void 0 ? 'outline' : _c, _d = _a.size, size = _d === void 0 ? 'large' : _d, text = _a.text, shape = _a.shape, logo_alignment = _a.logo_alignment, width = _a.width, locale = _a.locale, click_listener = _a.click_listener, containerProps = _a.containerProps, props = __rest(_a, ["onSuccess", "onError", "useOneTap", "promptMomentNotification", "type", "theme", "size", "text", "shape", "logo_alignment", "width", "locale", "click_listener", "containerProps"]);
var btnContainerRef = (0, react_1.useRef)(null);
var _e = (0, GoogleOAuthProvider_1.useGoogleOAuth)(), clientId = _e.clientId, scriptLoadedSuccessfully = _e.scriptLoadedSuccessfully;
var onSuccessRef = (0, react_1.useRef)(onSuccess);
onSuccessRef.current = onSuccess;
var onErrorRef = (0, react_1.useRef)(onError);
onErrorRef.current = onError;
var promptMomentNotificationRef = (0, react_1.useRef)(promptMomentNotification);
promptMomentNotificationRef.current = promptMomentNotification;
(0, react_1.useEffect)(function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
if (!scriptLoadedSuccessfully)
return;
(_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.google) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.initialize(__assign({ client_id: clientId, callback: function (credentialResponse) {
var _a;
if (!(credentialResponse === null || credentialResponse === void 0 ? void 0 : credentialResponse.credential)) {
return (_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef);
}
var credential = credentialResponse.credential, select_by = credentialResponse.select_by;
onSuccessRef.current({
credential: credential,
clientId: (0, utils_1.extractClientId)(credentialResponse),
select_by: select_by,
});
} }, props));
(_f = (_e = (_d = window === null || window === void 0 ? void 0 : window.google) === null || _d === void 0 ? void 0 : _d.accounts) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.renderButton(btnContainerRef.current, {
type: type,
theme: theme,
size: size,
text: text,
shape: shape,
logo_alignment: logo_alignment,
width: width,
locale: locale,
click_listener: click_listener,
});
if (useOneTap)
(_j = (_h = (_g = window === null || window === void 0 ? void 0 : window.google) === null || _g === void 0 ? void 0 : _g.accounts) === null || _h === void 0 ? void 0 : _h.id) === null || _j === void 0 ? void 0 : _j.prompt(promptMomentNotificationRef.current);
return function () {
var _a, _b, _c;
if (useOneTap)
(_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.google) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.cancel();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [clientId, scriptLoadedSuccessfully, useOneTap, type, theme, size, text, shape, logo_alignment, width, locale]);
return ((0, jsx_runtime_1.jsx)("div", __assign({}, containerProps, { ref: btnContainerRef, style: __assign({ height: containerHeightMap[size] }, containerProps === null || containerProps === void 0 ? void 0 : containerProps.style) })));
}
//# sourceMappingURL=GoogleLogin.js.map