()
| 269 | * login using the provided netlify API for oauth |
| 270 | */ |
| 271 | export function renderGithubLoginButton() { |
| 272 | const githubLoginWrapper = document.createElement('div'); |
| 273 | githubLoginWrapper.id = 'github-login-wrapper'; |
| 274 | githubLoginWrapper.innerHTML = |
| 275 | "<p>Using Netlify's OAuth client to retrieve your token, you'll see a simple GitHub graphql <code>monaco-graphql</code> Demo.</p>"; |
| 276 | const githubButton = document.createElement('button'); |
| 277 | |
| 278 | const logoutButton = document.createElement('button'); |
| 279 | |
| 280 | logoutButton.innerHTML = 'Logout'; |
| 281 | |
| 282 | logoutButton.onclick = async e => { |
| 283 | e.preventDefault(); |
| 284 | schemaFetcher.logout(); |
| 285 | await render(); |
| 286 | document |
| 287 | .getElementById('session-editor') |
| 288 | ?.setAttribute('style', 'display: none'); |
| 289 | document.getElementById('toolbar')?.setAttribute('style', 'display: none'); |
| 290 | }; |
| 291 | |
| 292 | if (schemaFetcher.token) { |
| 293 | document.getElementById('github-login-wrapper')?.remove(); |
| 294 | const toolbar = document.getElementById('toolbar'); |
| 295 | toolbar?.append(logoutButton); |
| 296 | } else { |
| 297 | githubLoginWrapper.append(githubButton); |
| 298 | document.getElementById('flex-wrapper')?.prepend(githubLoginWrapper); |
| 299 | } |
| 300 | |
| 301 | githubButton.id = 'login'; |
| 302 | githubButton.innerHTML = 'GitHub Login'; |
| 303 | |
| 304 | githubButton.onclick = e => { |
| 305 | e.preventDefault(); |
| 306 | // @ts-expect-error |
| 307 | const authenticator = new netlify.default({ site_id: SITE_ID }); |
| 308 | authenticator.authenticate( |
| 309 | { provider: 'github', scope: ['user'] }, |
| 310 | async (err: Error, data: { token: string }) => { |
| 311 | if (err) { |
| 312 | console.error('Error authenticating with GitHub:', err); |
| 313 | } else { |
| 314 | await schemaFetcher.setApiToken(data.token); |
| 315 | await render(); |
| 316 | } |
| 317 | }, |
| 318 | ); |
| 319 | }; |
| 320 | } |
no test coverage detected
searching dependent graphs…