mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-13 15:10:43 -03:00
arreglado lo de usuario que no se veia el nombre de usuario
This commit is contained in:
27
src/lib/hooks/obtenerUsuario.ts
Normal file
27
src/lib/hooks/obtenerUsuario.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user