/* Copyright (C) 2024 Manuel Bustillo*/

import { getCsrfToken } from '@/app/lib/utils';

export function login({ email, password, onLogin }: { email: string, password: string, onLogin: () => void }) {
  console.log(email, password);
  return fetch("/api/default/users/sign_in", {
    method: 'POST',
    body: JSON.stringify({ user: { email, password } }),
    headers: {
      'Content-Type': 'application/json',
      'X-CSRF-TOKEN': getCsrfToken(),
    }
  })
    .then(onLogin)
    .catch((error) => console.error(error));
} 