- Add UserFavorites MongoDB model with ObjectId references - Create authenticated API endpoints for favorites management - Add Heart icon and FavoriteButton components with toggle functionality - Display favorite button below recipe tags for logged-in users - Add Favoriten navigation link (visible only when authenticated) - Create favorites page with grid layout and search functionality - Store favorites by MongoDB ObjectId for data integrity 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
32 lines
775 B
TypeScript
32 lines
775 B
TypeScript
import type { PageServerLoad } from "./$types";
|
|
import { redirect } from '@sveltejs/kit';
|
|
|
|
export const load: PageServerLoad = async ({ fetch, locals }) => {
|
|
const session = await locals.auth();
|
|
|
|
if (!session?.user?.nickname) {
|
|
throw redirect(302, '/rezepte');
|
|
}
|
|
|
|
try {
|
|
const res = await fetch('/api/rezepte/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'
|
|
};
|
|
}
|
|
}; |