separada la logica de publicar el post a la del manejo del front

This commit is contained in:
2025-12-08 13:37:23 -03:00
parent dc94fc309d
commit 9cc5831cfc
2 changed files with 36 additions and 29 deletions

View File

@@ -0,0 +1,27 @@
import { addPost } from "@/stores/posts";
import { apiBase } from "@/stores/url";
import { sesionStore } from "@/stores/usuario";
import { get } from "svelte/store";
export async function publicarPost(formData: FormData){
try{
const req = fetch(get(apiBase) + '/api/posts', {
method: 'POST',
//credentials: 'include',
headers: {
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
},
body: formData
});
const res = await req;
if (res.ok) {
const post = await res.json();
addPost(post);
return '';
}
return 'No se pudo crear el post.';
} catch {
return 'Fallo al alcanzar el servidor';
}
}