const SESSION_URL = 'https://createsession-edvvp3hbnq-du.a.run.app';
const LOGOUT_URL = 'https://logout-edvvp3hbnq-du.a.run.app';

/**
 * Call Firebase Function to create session cookie.
 * Stores session in secure HTTP-only cookie via server.
 */
export async function createSession(idToken: string): Promise<void> {
  await $fetch(SESSION_URL, {
    method: 'POST',
    body: { idToken },
    credentials: 'include', // required to receive cookie
  });
}

/**
 * Call Firebase Function to clear session cookie.
 */
export async function logoutSession(): Promise<void> {
  await $fetch(LOGOUT_URL, {
    method: 'POST',
    credentials: 'include',
  });
}
