Consolidate auth routes under /auth and rename /u to /user
Moves the login screen from /login to /auth, logout from /logout to /auth/logout (alongside the existing /auth/login and /auth/callback endpoints), and the public profile route from /u/[id] to /user/[id]. AUTH_REDIRECT_URI and AUTH_POST_LOGOUT_URI already point at /auth/callback and / respectively, so no Zitadel config change is needed for the auth move.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = ({ locals, url }) => {
|
||||
if (locals.user) {
|
||||
redirect(302, url.searchParams.get('returnTo') ?? '/');
|
||||
}
|
||||
return { returnTo: url.searchParams.get('returnTo') ?? '/' };
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
<script lang="ts">
|
||||
import Button from '$lib/components/ui/primitives/Button.svelte';
|
||||
import Logo from '$lib/components/ui/primitives/Logo.svelte';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
const returnParam = $derived(`returnTo=${encodeURIComponent(data.returnTo)}`);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Iniciar sesión</title>
|
||||
<meta name="description" content="Inicia sesión o crea una cuenta en Musify." />
|
||||
</svelte:head>
|
||||
|
||||
<div class="relative grid min-h-screen place-items-center overflow-hidden bg-bg px-6 text-fg">
|
||||
<div class="pointer-events-none absolute inset-0" style="background:var(--mf-ambient)"></div>
|
||||
|
||||
<div class="relative flex w-full max-w-4xl flex-col items-center gap-12 text-center">
|
||||
<Logo size="lg" />
|
||||
|
||||
<div class="animate-enter flex flex-col items-center gap-5">
|
||||
<h1
|
||||
class="font-display text-[clamp(2.75rem,9vw,8rem)] leading-[1.05] font-semibold tracking-tight"
|
||||
>
|
||||
<span class="block">Tu música.</span>
|
||||
<span class="block">Sin límites.</span>
|
||||
</h1>
|
||||
<p class="text-lg text-fg-2">Inicia sesión para continuar.</p>
|
||||
</div>
|
||||
|
||||
<div class="flex w-full max-w-cta flex-col gap-3">
|
||||
<Button href={`/auth/login?${returnParam}`} reload size="lg" class="w-full">
|
||||
Iniciar sesión
|
||||
</Button>
|
||||
<Button
|
||||
href={`/auth/login?mode=register&${returnParam}`}
|
||||
reload
|
||||
variant="secondary"
|
||||
size="lg"
|
||||
class="w-full"
|
||||
>
|
||||
Crear cuenta
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,21 @@
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import * as client from 'openid-client';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { getOidcConfig, decodeSession, SESSION_COOKIE } from '$lib/server/auth';
|
||||
import { authConfig } from '$lib/server/config';
|
||||
|
||||
const handleLogout: RequestHandler = async ({ cookies }) => {
|
||||
const session = await decodeSession(cookies.get(SESSION_COOKIE));
|
||||
cookies.delete(SESSION_COOKIE, { path: '/' });
|
||||
|
||||
const config = await getOidcConfig();
|
||||
const endSessionUrl = client.buildEndSessionUrl(config, {
|
||||
post_logout_redirect_uri: authConfig.postLogoutUri,
|
||||
...(session?.idToken ? { id_token_hint: session.idToken } : {})
|
||||
});
|
||||
|
||||
redirect(302, endSessionUrl.href);
|
||||
};
|
||||
|
||||
export const GET = handleLogout;
|
||||
export const POST = handleLogout;
|
||||
Reference in New Issue
Block a user