Files
homepage/src/routes/[recipeLang=recipeLang]/admin/untranslated/+page.server.ts
T
Alexander c912afd46a perf: reuse locals.session from hook in all remaining routes
Extends the previous loader-only sweep across the full tree: every
remaining `await locals.auth()` now falls back through
`locals.session ?? await locals.auth()`, so the hook's cached result
is reused.

68 files, 107 sites touched — loaders, form actions, and API
endpoints across cospend / tasks / fitness / faith / recipe / admin.
hooks.server.ts is intentionally left alone since it's the originating
call that populates locals.session in the first place.
2026-04-23 15:08:10 +02:00

47 lines
1.2 KiB
TypeScript

import type { PageServerLoad } from "./$types";
import { redirect } from '@sveltejs/kit';
import { errorWithVerse } from '$lib/server/errorQuote';
export const load: PageServerLoad = async ({ fetch, locals, url, params }) => {
const session = locals.session ?? await locals.auth();
// Redirect to login if not authenticated
if (!session?.user?.nickname) {
const callbackUrl = encodeURIComponent(url.pathname);
throw redirect(302, `/login?callbackUrl=${callbackUrl}`);
}
// Check user group permission
if (!session.user.groups?.includes('rezepte_users')) {
await errorWithVerse(fetch, url.pathname, 403, 'Zugriff verweigert. Du hast keine Berechtigung für diesen Bereich.');
}
try {
const res = await fetch('/api/rezepte/translate/untranslated');
if (!res.ok) {
return {
untranslated: [],
session,
recipeLang: params.recipeLang,
error: 'Fehler beim Laden der unübersetzten Rezepte'
};
}
const untranslated = await res.json();
return {
untranslated,
session,
recipeLang: params.recipeLang
};
} catch (e) {
return {
untranslated: [],
session,
recipeLang: params.recipeLang,
error: 'Fehler beim Laden der unübersetzten Rezepte'
};
}
};