feat: add Twitch account authorization controls

This commit is contained in:
2026-10-25 04:37:08 +01:00
parent 8c8d632557
commit 05d7947a29
2 changed files with 81 additions and 1 deletions
+51 -1
View File
@@ -12,6 +12,10 @@
let newPassword = '';
let authError = '';
let authBusy = false;
let oauthLink = '';
let oauthIdentity: 'streamer' | 'bot' = 'streamer';
let oauthBusy = false;
let oauthError = '';
async function checkServer() {
connectionState = 'CONNECTING';
@@ -82,6 +86,33 @@
sessionToken = '';
authenticated = false;
mustReplaceCredentials = false;
oauthLink = '';
}
async function createOAuthLink(identity: 'streamer' | 'bot') {
oauthBusy = true;
oauthError = '';
oauthIdentity = identity;
oauthLink = '';
try {
const response = await fetch(`${serverAddress}/api/v1/twitch/oauth/link?identity=${identity}`, {
headers: { authorization: `Bearer ${sessionToken}` },
});
if (!response.ok) throw new Error('The server could not create the Twitch authorization link.');
const result: { authorization_url: string } = await response.json();
oauthLink = result.authorization_url;
} catch (error) {
oauthError = error instanceof Error ? error.message : 'The Twitch authorization link could not be created.';
} finally {
oauthBusy = false;
}
}
async function copyOAuthLink() {
if (!oauthLink) return;
await navigator.clipboard.writeText(oauthLink).catch(() => {
oauthError = 'Copy was unavailable. Select and copy the link manually.';
});
}
</script>
@@ -122,7 +153,26 @@
{#if authError}<div class="auth-error">{authError}</div>{/if}
{/if}
</div>
<div class="side-section"><div class="micro">CHANNEL</div><div class="empty-row">No Twitch account connected</div></div>
<div class="side-section channel-section">
<div class="micro">TWITCH ACCOUNTS</div>
{#if authenticated}
<div class="oauth-actions">
<button class="secondary-action" onclick={() => createOAuthLink('streamer')} disabled={oauthBusy}>CONNECT STREAMER</button>
<button class="secondary-action" onclick={() => createOAuthLink('bot')} disabled={oauthBusy}>CONNECT BOT</button>
</div>
{#if oauthLink}
<div class="oauth-link-card">
<div class="micro">{oauthIdentity.toUpperCase()} AUTHORIZATION LINK</div>
<textarea class="oauth-link" readonly value={oauthLink} aria-label="Twitch authorization link"></textarea>
<button class="primary control-button" onclick={copyOAuthLink}>COPY LINK</button>
<div class="oauth-hint">Open the copied link in the intended Twitch account session. It expires in 10 minutes.</div>
</div>
{/if}
{#if oauthError}<div class="auth-error">{oauthError}</div>{/if}
{:else}
<div class="empty-row">Sign in as administrator to connect accounts.</div>
{/if}
</div>
<div class="side-section side-footer"><div class="micro">SERVER VERSION</div><div class="mono">{serverVersion}</div></div>
</aside>