Private
Public Access
primer draft de la pagina
This commit is contained in:
1 parent
02a6c846dc
commit
fcc3952841
42 files changed
+1248
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import type { User } from '../../types';
|
||||
import { API_URL } from '../env';
|
||||
|
||||
async function handleResponse<T>(response: Response): Promise<T> {
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ message: 'Error desconocido' }));
|
||||
throw new Error(error.message || 'Error en la petición');
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
function getToken(): string {
|
||||
if (typeof window !== 'undefined') {
|
||||
return localStorage.getItem('token') || '';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export async function getUsers(): Promise<User[]> {
|
||||
const response = await fetch(`${API_URL}/users`, {
|
||||
headers: { Authorization: `Bearer ${getToken()}` }
|
||||
});
|
||||
return handleResponse<User[]>(response);
|
||||
}
|
||||
Reference in new issue
Block a user