()
| 56 | .google?.accounts?.id; |
| 57 | |
| 58 | const 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 |
no test coverage detected