27 lines
605 B
TypeScript
27 lines
605 B
TypeScript
import { API_URL } from '$env/static/private';
|
|
import { redirect } from '@sveltejs/kit';
|
|
|
|
import type { PageServerLoad } from './$types';
|
|
|
|
import type { Leaderboard } from '$lib/types';
|
|
import { handleRedirect } from '$lib/utils';
|
|
|
|
export const load = (async ({ url, locals: { user }, fetch }) => {
|
|
|
|
if (!user) redirect(302, handleRedirect('login', url));
|
|
|
|
const res = await fetch(`${API_URL}/leaderboard`);
|
|
|
|
if (!res.ok) {
|
|
return {
|
|
leaderboard: []
|
|
};
|
|
}
|
|
|
|
const leaderboard = (await res.json()) as Leaderboard[];
|
|
|
|
return {
|
|
title: 'Classement',
|
|
leaderboard
|
|
};
|
|
}) satisfies PageServerLoad;
|