34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
export * from '@/lib/db';
|
|
|
|
export const fetchPostDetailsAPI = async (id: string, options: { sizes?: string, formats?: string } = {}) => {
|
|
const params = new URLSearchParams();
|
|
if (options.sizes) params.set('sizes', options.sizes);
|
|
if (options.formats) params.set('formats', options.formats);
|
|
|
|
const qs = params.toString();
|
|
const url = `/api/posts/${id}${qs ? `?${qs}` : ''}`;
|
|
|
|
// We rely on the browser/hook to handle auth headers if global fetch is intercepted,
|
|
// OR we explicitly get session?
|
|
// Usually standard `fetch` in our app might not send auth if using implicit flows or we need to pass headers.
|
|
// In `useFeedData`, we manually added headers.
|
|
// Let's assume we need to handle auth here or use a helper that does.
|
|
// To keep it simple for now, we'll import `supabase` and get session.
|
|
|
|
const { supabase } = await import('@/integrations/supabase/client');
|
|
const { data: { session } } = await supabase.auth.getSession();
|
|
|
|
const headers: Record<string, string> = {};
|
|
if (session?.access_token) {
|
|
headers['Authorization'] = `Bearer ${session.access_token}`;
|
|
}
|
|
|
|
const res = await fetch(url, { headers });
|
|
if (!res.ok) {
|
|
if (res.status === 404) return null;
|
|
throw new Error(`Failed to fetch post: ${res.statusText}`);
|
|
}
|
|
|
|
return res.json();
|
|
};
|