arreglado lo de usuario que no se veia el nombre de usuario

This commit is contained in:
2025-11-27 17:30:52 -03:00
parent 17addc8fcf
commit 0b39cc6f28
5 changed files with 72 additions and 4 deletions

View File

@@ -0,0 +1,27 @@
import { apiBase } from '@/stores/url';
import type { UserResponseDto } from '../../types';
import { get } from 'svelte/store';
import { sesionStore } from '@/stores/usuario';
export async function obtenerUsuarioPorUsername(username: string): Promise<UserResponseDto | null> {
try {
const response = await fetch(`${get(apiBase)}/api/users/username/${username}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
if (!response.ok) {
//console.error('Error fetching user data:', response.status);
return null;
}
const user: UserResponseDto = await response.json();
return user;
} catch (error) {
//console.error('Failed to reach the server while fetching user:', error);
return null;
}
}