Spaces:
Running
Running
File size: 1,098 Bytes
117cde0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | /**
* Backend auth bridge — mirrors Supabase auth to HttpOnly cookies (issue #130).
*/
import { supabase } from './supabase';
export const BACKEND_URL =
process.env.EXPO_PUBLIC_BACKEND_URL || 'https://ritesh19180-ai-helpdesk-api.hf.space';
const safeFetch = async (path, init = {}) => {
try {
return await fetch(`${BACKEND_URL}${path}`, {
credentials: 'include',
...init,
headers: { 'Content-Type': 'application/json', ...(init.headers || {}) },
});
} catch (e) {
console.warn(`[authBackend] ${path} failed:`, e?.message || e);
return null;
}
};
export const backendLogin = (email, password) =>
safeFetch('/auth/login', {
method: 'POST',
body: JSON.stringify({ email, password }),
});
export const backendLogout = () => safeFetch('/auth/logout', { method: 'POST' });
/** Bearer fallback when native cookie jar is unavailable. */
export const getAuthHeaders = async () => {
const { data } = await supabase.auth.getSession();
const token = data?.session?.access_token;
return token ? { Authorization: `Bearer ${token}` } : {};
};
|