fetch de usuarios ya funcional junto con la ui de usurios

This commit is contained in:
2025-11-27 20:11:21 -03:00
parent f31b2ab7b1
commit 535723900d
5 changed files with 75 additions and 33 deletions

View File

@@ -0,0 +1,29 @@
import { apiBase } from '@/stores/url.js';
import { sesionStore } from '@/stores/usuario';
import { redirect } from '@sveltejs/kit';
import { get } from 'svelte/store';
import type { UserResponseDto } from '../../../types.js';
//para que solo se envie cuando se requiere
export const prerender = true;
export async function load({}) {
const response = await fetch(get(apiBase) + '/api/admin/users', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
if (response.status === 401) {
throw redirect(302, '/');
}
if (!response.ok) {
return { error: true };
}
const usuarios: UserResponseDto[] = await response.json();
return { usuarios, error: false };
}