-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
40 lines (38 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function googleOneTap(
{
client_id,
auto_select = false,
cancel_on_tap_outside = false,
context = "signin",
...otherOptions
},
callback
) {
if (!client_id) {
throw new Error("client_id is required");
}
if (typeof window !== "undefined" && window.document) {
const contextValue = ["signin", "signup", "use"].includes(context)
? context
: "signin";
const googleScript = document.createElement("script");
googleScript.src = "https://accounts.google.com/gsi/client";
googleScript.async = true;
googleScript.defer = true;
document.head.appendChild(googleScript);
window.onload = function () {
if (window.google) {
window.google.accounts.id.initialize({
client_id: client_id,
callback: callback,
auto_select: auto_select,
cancel_on_tap_outside: cancel_on_tap_outside,
context: contextValue,
...otherOptions,
});
window.google.accounts.id.prompt();
}
};
}
}
module.exports = googleOneTap;