From 3eaa3dd233bfb36d2c43e272ffc487d89109fa4a Mon Sep 17 00:00:00 2001 From: maxDorninger <97409287+maxDorninger@users.noreply.github.com> Date: Sun, 7 Sep 2025 21:01:24 +0200 Subject: [PATCH] update how login is handled in the frontend --- web/src/lib/api/api.d.ts | 6 +- web/src/lib/components/login-card.svelte | 249 ++++++++++----------- web/src/lib/components/signup-card.svelte | 261 ++++++++++------------ web/src/lib/utils.ts | 20 +- web/src/routes/login/+layout.svelte | 2 +- web/src/routes/login/+layout.ts | 2 +- web/src/routes/login/+page.svelte | 4 +- web/src/routes/login/signup/+page.svelte | 4 +- 8 files changed, 260 insertions(+), 288 deletions(-) diff --git a/web/src/lib/api/api.d.ts b/web/src/lib/api/api.d.ts index 4ab7acc..05c4cea 100644 --- a/web/src/lib/api/api.d.ts +++ b/web/src/lib/api/api.d.ts @@ -2313,11 +2313,7 @@ export interface operations { }; cookie?: never; }; - requestBody?: { - content: { - "application/json": string[]; - }; - }; + requestBody?: never; responses: { /** @description Successful Response */ 200: { diff --git a/web/src/lib/components/login-card.svelte b/web/src/lib/components/login-card.svelte index 4c8600f..00a2c00 100644 --- a/web/src/lib/components/login-card.svelte +++ b/web/src/lib/components/login-card.svelte @@ -1,146 +1,129 @@ - - Login - Enter your email below to log in to your account - - -
-
- - -
-
- - -
+ + Login + Enter your email below to log in to your account + + + +
+ + +
+
+ + +
- {#if errorMessage} - - - Error - {errorMessage} - - {/if} - {#if isLoading} - - {/if} - - - {#await oauthProvider} - - {:then result} - {#if result.oauth_name != null} -
- - Or continue with - -
- - {/if} - {/await} -
- -
-
+ {#if errorMessage} + + + Error + {errorMessage} + + {/if} + + {#if isLoading} + + {/if} + + + {#each oauthProviderNames as name (name)} +
+ + Or continue with + +
+ + {/each} +
+ +
+
diff --git a/web/src/lib/components/signup-card.svelte b/web/src/lib/components/signup-card.svelte index 35f1943..626928f 100644 --- a/web/src/lib/components/signup-card.svelte +++ b/web/src/lib/components/signup-card.svelte @@ -1,148 +1,131 @@ - - Sign Up - Enter your information to create an account - - -
-
- - -
-
- - -
-
- - -
- {#if errorMessage} - - - Error - {errorMessage} - - {/if} - {#if successMessage} - - - Success - {successMessage} - - {/if} - {#if isLoading} - - {/if} - - - {#await oauthProvider} - - {:then result} - {#if result.oauth_name != null} -
- - Or continue with - -
- - {/if} - {/await} -
- -
-
+ + Sign Up + Enter your information to create an account + + +
+
+ + +
+
+ + +
+
+ + +
+ {#if errorMessage} + + + Error + {errorMessage} + + {/if} + {#if successMessage} + + + Success + {successMessage} + + {/if} + {#if isLoading} + + {/if} + + + {#each oauthProviderNames as name (name)} +
+ + Or continue with + +
+ + {/each} +
+ +
+
diff --git a/web/src/lib/utils.ts b/web/src/lib/utils.ts index 6e61d21..5696f4f 100644 --- a/web/src/lib/utils.ts +++ b/web/src/lib/utils.ts @@ -59,12 +59,22 @@ export function convertTorrentSeasonRangeToIntegerRange(torrent: { } export async function handleLogout() { - const { error } = await client.POST('/api/v1/auth/cookie/logout'); - if (error) { - toast.error('Logout failed'); + await client.POST('/api/v1/auth/cookie/logout'); + await goto(base + '/login'); +} + +export async function handleOauth(oauth_name: string) { + const {error, data} = await client.GET(`/api/v1/auth/oauth/{openid_provider_name}/authorize`, { + params: { + path:{ + openid_provider_name: oauth_name + } + } + }); + if (!error && data?.authorization_url) { + window.location.href = data.authorization_url; } else { - toast.success('Logout successful!'); - await goto(base + '/login'); + toast.error("Failed to initiate OAuth login."); } } diff --git a/web/src/routes/login/+layout.svelte b/web/src/routes/login/+layout.svelte index 32f9266..58dc660 100644 --- a/web/src/routes/login/+layout.svelte +++ b/web/src/routes/login/+layout.svelte @@ -8,7 +8,7 @@ import { page } from '$app/state'; import { setContext } from 'svelte'; - setContext('oauthProvider', () => page.data.oauthProvider); + setContext('oauthProviders', () => page.data.oauthProviders); let { children } = $props(); diff --git a/web/src/routes/login/+layout.ts b/web/src/routes/login/+layout.ts index 2c7c0e6..ca0701d 100644 --- a/web/src/routes/login/+layout.ts +++ b/web/src/routes/login/+layout.ts @@ -3,5 +3,5 @@ import client from '$lib/api'; export const load: LayoutLoad = async ({ fetch }) => { const { data } = await client.GET('/api/v1/auth/metadata', { fetch: fetch }); - return { oauthProvider: data }; + return { oauthProviders: data }; }; diff --git a/web/src/routes/login/+page.svelte b/web/src/routes/login/+page.svelte index df774b7..9e794a2 100644 --- a/web/src/routes/login/+page.svelte +++ b/web/src/routes/login/+page.svelte @@ -2,7 +2,7 @@ import LoginCard from '$lib/components/login-card.svelte'; import { getContext } from 'svelte'; - let oauthProvider: () => { oauth_name: string } = getContext('oauthProvider'); + let oauthProvider: () => string[] = getContext('oauthProviders'); @@ -14,5 +14,5 @@
- +
diff --git a/web/src/routes/login/signup/+page.svelte b/web/src/routes/login/signup/+page.svelte index 723969b..14e0464 100644 --- a/web/src/routes/login/signup/+page.svelte +++ b/web/src/routes/login/signup/+page.svelte @@ -2,7 +2,7 @@ import SignupCard from '$lib/components/signup-card.svelte'; import { getContext } from 'svelte'; - let oauthProvider: () => { oauth_name: string } = getContext('oauthProvider'); + let oauthProvider: () => string[] = getContext('oauthProviders'); @@ -10,4 +10,4 @@ - +