1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-30 10:19:37 +02:00
AdventureLog/frontend/src/routes/collections/archived/+page.server.ts

34 lines
941 B
TypeScript
Raw Normal View History

2024-08-07 13:01:12 -04:00
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
import type { Adventure } from '$lib/types';
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
export const load = (async (event) => {
if (!event.locals.user) {
return redirect(302, '/login');
} else {
2024-11-29 18:20:51 -05:00
let sessionId = event.cookies.get('sessionid');
2024-08-07 13:01:12 -04:00
let adventures: Adventure[] = [];
let initialFetch = await fetch(`${serverEndpoint}/api/collections/archived/`, {
headers: {
2024-11-29 18:20:51 -05:00
Cookie: `sessionid=${sessionId}`
2024-08-07 13:01:12 -04:00
}
});
if (!initialFetch.ok) {
console.error('Failed to fetch visited adventures');
return redirect(302, '/login');
} else {
let res = await initialFetch.json();
let visited = res as Adventure[];
adventures = [...adventures, ...visited];
}
return {
props: {
adventures
}
};
}
}) satisfies PageServerLoad;