mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-20 16:17:32 -03:00
28 lines
808 B
TypeScript
28 lines
808 B
TypeScript
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;
|
|
}
|
|
}
|