hookshot/web/oauth.tsx
Will Hunt 55529d7128
Add support for OAuth login to GitHub via widget (including adding new installations) (#661)
* WIP

* Update vite

* Add oauth landing page

* Add API support for GitHub oauthing

* Remove console.logs

* Add support for logging and and out of GitHub

* Add bridge API methods

* Add base link styling

* Sugar syntax main get

* Update vite

* changelog

* Review changes

* Use instance to match UI

* lint

---------

Co-authored-by: Justin Carlson <justinc@element.io>
2023-03-14 10:50:46 +00:00

40 lines
1018 B
TypeScript

import "./fonts/fonts.scss"
import "./styling.scss";
import "./oauth.scss";
import { render } from 'preact';
import 'preact/devtools';
const root = document.getElementsByTagName('main')[0];
const ServiceToName: Record<string,string> = {
github: 'GitHub',
gitlab: 'GitLab',
default: ''
}
function RenderOAuth() {
const params = new URLSearchParams(window.location.search);
const service = params.get('service') ?? 'default';
const error = params.get('error');
const errcode = params.get('errcode');
const oauthKind = params.get('oauth-kind') ?? 'account';
if (error) {
return <>
<h1>Could not connect your { ServiceToName[service] } {oauthKind} to Hookshot.</h1>
<p>
<code>{errcode}</code> {error}
</p>
</>;
}
return <>
<h1>Your { ServiceToName[service] } {oauthKind} has been connected.</h1>
<p>You may close this window.</p>
</>;
}
if (root) {
render(<RenderOAuth />, root);
}