MCPcopy Create free account
hub / github.com/dailydotdev/apps / loadGsiScript

Function loadGsiScript

packages/shared/src/hooks/auth/useGoogleOneTap.ts:58–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56 .google?.accounts?.id;
57
58const loadGsiScript = (): Promise<void> =>
59 new Promise((resolve, reject) => {
60 if (getGoogleId()) {
61 resolve();
62 return;
63 }
64
65 const existing = document.getElementById(
66 GSI_SCRIPT_ID,
67 ) as HTMLScriptElement | null;
68 if (existing) {
69 existing.addEventListener('load', () => resolve());
70 existing.addEventListener('error', () =>
71 reject(new Error('Failed to load Google Identity Services')),
72 );
73 return;
74 }
75
76 const script = document.createElement('script');
77 script.id = GSI_SCRIPT_ID;
78 script.src = GSI_SRC;
79 script.async = true;
80 script.defer = true;
81 script.addEventListener('load', () => resolve());
82 script.addEventListener('error', () =>
83 reject(new Error('Failed to load Google Identity Services')),
84 );
85 document.head.appendChild(script);
86 });
87
88// `initialize()` is meant to run once per page: GSI warns and can misbehave
89// when it is called again. Initialize once and route the credential to the

Callers 1

initFunction · 0.85

Calls 1

getGoogleIdFunction · 0.85

Tested by

no test coverage detected