mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-20 21:05:15 +02:00
35 lines
686 B
TypeScript
35 lines
686 B
TypeScript
import {env} from '$env/dynamic/public';
|
|
import type {PageLoad} from './$types';
|
|
|
|
const apiUrl = env.PUBLIC_API_URL;
|
|
export const load: PageLoad = async ({fetch}) => {
|
|
try {
|
|
const users = await fetch(apiUrl + '/users/all', {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
credentials: 'include'
|
|
});
|
|
|
|
if (!users.ok) {
|
|
console.error(`Failed to fetch users: ${users.statusText}`);
|
|
return {
|
|
users: null
|
|
};
|
|
}
|
|
|
|
const usersData = await users.json();
|
|
console.log('Fetched users:', usersData);
|
|
|
|
return {
|
|
users: usersData
|
|
};
|
|
} catch (error) {
|
|
console.error('Error fetching users:', error);
|
|
return {
|
|
users: null
|
|
};
|
|
}
|
|
};
|