user stats

This commit is contained in:
Sean Morley
2024-07-10 18:05:12 -04:00
parent bb1f2d92cf
commit b3878bff72
3 changed files with 93 additions and 6 deletions

View File

@@ -1,11 +1,27 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad, RequestEvent } from '../$types';
import { PUBLIC_SERVER_URL } from '$env/static/public';
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
export const load: PageServerLoad = async (event: RequestEvent) => {
if (!event.locals.user) {
if (!event.locals.user || !event.cookies.get('auth')) {
return redirect(302, '/login');
}
let stats = null;
let res = await event.fetch(`${endpoint}/api/stats/counts/`, {
headers: {
Cookie: `${event.cookies.get('auth')}`
}
});
if (!res.ok) {
console.error('Failed to fetch user stats');
} else {
stats = await res.json();
}
return {
user: event.locals.user
user: event.locals.user,
stats
};
};