mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-02 13:20:43 -03:00
21 lines
600 B
TypeScript
21 lines
600 B
TypeScript
import { apiBase } from '@/stores/url';
|
|
import { sesionStore } from '@/stores/usuario';
|
|
import { get } from 'svelte/store';
|
|
import type { Post } from '../../types';
|
|
import { PAGE_SIZE } from '../stores/posts';
|
|
|
|
export async function getPosts(page: number = 1): Promise<Post[]> {
|
|
const token = get(sesionStore)?.accessToken;
|
|
|
|
const headers: HeadersInit = {};
|
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
|
|
const res = await fetch(`${get(apiBase)}/timeline?page=${page}&pageSize=${PAGE_SIZE}`, {
|
|
headers
|
|
});
|
|
|
|
if (!res.ok) throw new Error('Error cargando posts');
|
|
|
|
return res.json();
|
|
}
|