mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-18 15:57:31 -03:00
hecha functionalidad para seguir usuarios desde los posts
This commit is contained in:
26
src/lib/hooks/esSeguido.ts
Normal file
26
src/lib/hooks/esSeguido.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { sesionStore } from '@/stores/usuario';
|
||||
import { get } from 'svelte/store';
|
||||
import type { Post } from '../../types';
|
||||
import { apiBase } from '@/stores/url';
|
||||
|
||||
export async function esSeguido(post: Post) {
|
||||
if (!get(sesionStore)?.accessToken || post.authorName === '[deleted]') return;
|
||||
|
||||
const id = post.authorId;
|
||||
try {
|
||||
const response = await fetch(`${get(apiBase)}/api/users/${id}/is-following`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user