infinity-forge
Version:
64 lines • 3.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = useGoogleOneTapLogin;
var react_1 = require("react");
var GoogleOAuthProvider_1 = require("../GoogleOAuthProvider.js");
var utils_1 = require("../utils/index.js");
function useGoogleOneTapLogin(_a) {
var onSuccess = _a.onSuccess, onError = _a.onError, promptMomentNotification = _a.promptMomentNotification, cancel_on_tap_outside = _a.cancel_on_tap_outside, prompt_parent_id = _a.prompt_parent_id, state_cookie_domain = _a.state_cookie_domain, hosted_domain = _a.hosted_domain, _b = _a.use_fedcm_for_prompt, use_fedcm_for_prompt = _b === void 0 ? false : _b, _c = _a.use_fedcm_for_button, use_fedcm_for_button = _c === void 0 ? false : _c, disabled = _a.disabled, auto_select = _a.auto_select;
var _d = (0, GoogleOAuthProvider_1.useGoogleOAuth)(), clientId = _d.clientId, scriptLoadedSuccessfully = _d.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;
if (disabled) {
(_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();
return;
}
(_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.initialize({
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,
});
},
hosted_domain: hosted_domain,
cancel_on_tap_outside: cancel_on_tap_outside,
prompt_parent_id: prompt_parent_id,
state_cookie_domain: state_cookie_domain,
use_fedcm_for_prompt: use_fedcm_for_prompt,
use_fedcm_for_button: use_fedcm_for_button,
auto_select: auto_select,
});
(_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;
(_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();
};
}, [
clientId,
scriptLoadedSuccessfully,
cancel_on_tap_outside,
prompt_parent_id,
state_cookie_domain,
hosted_domain,
use_fedcm_for_prompt,
use_fedcm_for_button,
disabled,
auto_select,
]);
}
//# sourceMappingURL=useGoogleOneTapLogin.js.map