feat(frontend): discord registration/login/linking

also moves the registration form found on the mastodon callback page
into a component so we're not repeating the same code for every auth method
This commit is contained in:
sam 2024-11-28 21:35:55 +01:00
parent 4780be3019
commit de733a0682
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
19 changed files with 545 additions and 212 deletions

View file

@ -0,0 +1,7 @@
import { apiRequest } from "$api";
import type { AuthUrls } from "$api/models/auth";
export const load = async ({ fetch }) => {
const urls = await apiRequest<AuthUrls>("POST", "/auth/urls", { fetch, isInternal: true });
return { urls };
};

View file

@ -0,0 +1,65 @@
<script lang="ts">
import AuthMethodList from "$components/settings/AuthMethodList.svelte";
import AuthMethodRow from "$components/settings/AuthMethodRow.svelte";
import type { PageData } from "./$types";
type Props = { data: PageData };
let { data }: Props = $props();
let max = $derived(data.meta.limits.max_auth_methods);
let canRemove = $derived(data.user.auth_methods.length > 1);
let emails = $derived(data.user.auth_methods.filter((m) => m.type === "EMAIL"));
let discordAccounts = $derived(data.user.auth_methods.filter((m) => m.type === "DISCORD"));
let googleAccounts = $derived(data.user.auth_methods.filter((m) => m.type === "GOOGLE"));
let tumblrAccounts = $derived(data.user.auth_methods.filter((m) => m.type === "TUMBLR"));
let fediAccounts = $derived(data.user.auth_methods.filter((m) => m.type === "FEDIVERSE"));
</script>
{#if data.urls.email_enabled}
<h3>Email addresses</h3>
<AuthMethodList
methods={emails}
{canRemove}
{max}
buttonLink="/settings/auth/add-email"
buttonText="Add email address"
/>
{/if}
{#if data.urls.discord}
<h3>Discord accounts</h3>
<AuthMethodList
methods={discordAccounts}
{canRemove}
{max}
buttonLink="/settings/auth/add-discord"
buttonText="Link Discord account"
/>
{/if}
{#if data.urls.google}
<h3>Google accounts</h3>
<AuthMethodList
methods={googleAccounts}
{canRemove}
{max}
buttonLink="/settings/auth/add-google"
buttonText="Link Google account"
/>
{/if}
{#if data.urls.tumblr}
<h3>Tumblr accounts</h3>
<AuthMethodList
methods={tumblrAccounts}
{canRemove}
{max}
buttonLink="/settings/auth/add-tumblr"
buttonText="Link Tumblr account"
/>
{/if}
<h3>Fediverse accounts</h3>
<AuthMethodList
methods={fediAccounts}
{canRemove}
{max}
buttonLink="/settings/auth/add-fediverse"
buttonText="Link Fediverse account"
/>

View file

@ -0,0 +1,12 @@
import { apiRequest } from "$api";
import { redirect } from "@sveltejs/kit";
export const load = async ({ fetch, cookies }) => {
const { url } = await apiRequest<{ url: string }>("GET", "/auth/discord/add-account", {
isInternal: true,
fetch,
cookies,
});
redirect(303, url);
};