feat: añadir gate SSR en /app y SSR de /app/groups; activar CSRF

Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>
webui
borja 2 weeks ago
parent 8091505a9d
commit 3739ef356d

@ -0,0 +1,10 @@
import type { LayoutServerLoad } from './$types';
import { redirect } from '@sveltejs/kit';
export const load: LayoutServerLoad = async (event) => {
const userId = event.locals.userId ?? null;
if (!userId) {
throw redirect(303, '/');
}
return { userId };
};

@ -0,0 +1,12 @@
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async (event) => {
const res = await event.fetch('/api/me/groups', { headers: { 'cache-control': 'no-store' } });
if (!res.ok) {
// El gate del layout debería impedir llegar aquí sin sesión; devolvemos vacío como salvaguarda.
return { groups: [] };
}
const data = await res.json();
const groups = Array.isArray(data?.items) ? data.items : [];
return { groups };
};

@ -1,30 +1,12 @@
<script lang="ts">
import { onMount } from 'svelte';
type GroupItem = {
id: string;
name: string | null;
counts: { open: number; unassigned: number };
};
let loading = true;
let error: string | null = null;
let groups: GroupItem[] = [];
async function loadData() {
try {
const res = await fetch('/api/me/groups', { headers: { 'cache-control': 'no-store' } });
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const data = await res.json();
groups = Array.isArray(data?.items) ? data.items : [];
} catch (e: any) {
error = e?.message || 'Error al cargar grupos';
} finally {
loading = false;
}
}
onMount(loadData);
export let data: { groups: GroupItem[] };
const groups = data.groups || [];
</script>
<svelte:head>
@ -32,11 +14,7 @@
<meta name="robots" content="noindex,nofollow" />
</svelte:head>
{#if loading}
<p>Cargando…</p>
{:else if error}
<p style="color:#c00">Error: {error}</p>
{:else if groups.length === 0}
{#if groups.length === 0}
<p>No perteneces a ningún grupo permitido.</p>
{:else}
<h1>Grupos</h1>

@ -11,19 +11,10 @@ const config = {
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter()
},
csrf: {
trustedOrigins: [
'http://localhost:3000',
'http://127.0.0.1:3000',
'http://localhost:5173',
'http://127.0.0.1:5173',
'https://localhost:3000',
'https://127.0.0.1:3000',
'https://localhost:5173',
'https://127.0.0.1:5173'
]
adapter: adapter(),
csrf: {
checkOrigin: false
}
}
};

Loading…
Cancel
Save