add route matcher to fix /login and /logout routes
Some checks failed
CI / update (push) Failing after 2m52s

Use SvelteKit param matcher to constrain [recipeLang] to only match
'recipes' or 'rezepte', preventing it from catching /login, /logout,
and other non-recipe routes.
This commit is contained in:
2025-12-26 22:48:01 +01:00
parent 9cd990f1b9
commit 3e43b731c9
34 changed files with 5 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import type { PageServerLoad } from "./$types";
import { redirect } from '@sveltejs/kit';
export const load: PageServerLoad = async ({ fetch, locals, params }) => {
const isEnglish = params.recipeLang === 'recipes';
const apiBase = isEnglish ? '/api/recipes' : '/api/rezepte';
const session = await locals.auth();
if (!session?.user?.nickname) {
throw redirect(302, `/${params.recipeLang}`);
}
try {
const res = await fetch(`${apiBase}/favorites/recipes`);
if (!res.ok) {
return {
favorites: [],
error: 'Failed to load favorites'
};
}
const favorites = await res.json();
return {
favorites,
session
};
} catch (e) {
return {
favorites: [],
error: 'Failed to load favorites'
};
}
};

View File

@@ -0,0 +1,79 @@
<script lang="ts">
import type { PageData } from './$types';
import '$lib/css/nordtheme.css';
import Recipes from '$lib/components/Recipes.svelte';
import Card from '$lib/components/Card.svelte';
import Search from '$lib/components/Search.svelte';
let { data }: { data: PageData } = $props();
let current_month = new Date().getMonth() + 1;
const isEnglish = $derived(data.lang === 'en');
const labels = $derived({
title: isEnglish ? 'Favorites' : 'Favoriten',
pageTitle: isEnglish ? 'My Favorites - Bocken Recipes' : 'Meine Favoriten - Bocken Rezepte',
metaDescription: isEnglish
? 'My favorite recipes from Bocken\'s kitchen.'
: 'Meine favorisierten Rezepte aus der Bockenschen Küche.',
count: isEnglish
? `${data.favorites.length} favorite recipe${data.favorites.length !== 1 ? 's' : ''}`
: `${data.favorites.length} favorisierte Rezepte`,
noFavorites: isEnglish ? 'No favorites saved yet' : 'Noch keine Favoriten gespeichert',
errorLoading: isEnglish ? 'Error loading favorites:' : 'Fehler beim Laden der Favoriten:',
emptyState1: isEnglish
? 'You haven\'t saved any recipes as favorites yet.'
: 'Du hast noch keine Rezepte als Favoriten gespeichert.',
emptyState2: isEnglish
? 'Visit a recipe and click the heart icon to add it to your favorites.'
: 'Besuche ein Rezept und klicke auf das Herz-Symbol, um es zu deinen Favoriten hinzuzufügen.',
recipesLink: isEnglish ? 'recipe' : 'Rezept'
});
</script>
<style>
h1{
text-align: center;
margin-bottom: 0;
font-size: 4rem;
}
.subheading{
text-align: center;
margin-top: 0;
font-size: 1.5rem;
}
.empty-state{
text-align: center;
margin-top: 3rem;
color: var(--nord3);
}
</style>
<svelte:head>
<title>{labels.pageTitle}</title>
<meta name="description" content={labels.metaDescription} />
</svelte:head>
<h1>{labels.title}</h1>
<p class=subheading>
{#if data.favorites.length > 0}
{labels.count}
{:else}
{labels.noFavorites}
{/if}
</p>
<Search favoritesOnly={true} lang={data.lang}></Search>
{#if data.error}
<p class="empty-state">{labels.errorLoading} {data.error}</p>
{:else if data.favorites.length > 0}
<Recipes>
{#each data.favorites as recipe}
<Card {recipe} {current_month} isFavorite={true} showFavoriteIndicator={true} routePrefix="/{data.recipeLang}"></Card>
{/each}
</Recipes>
{:else}
<div class="empty-state">
<p>{labels.emptyState1}</p>
<p><a href="/{data.recipeLang}">{labels.emptyState2}</a></p>
</div>
{/if}