export const login = async (phoneNumber) => {
  const response = await fetch(`http://localhost:3000/users?phoneNumber=${phoneNumber}`);
  const users = await response.json();
  if (users.length > 0) {
    const user = users[0];
    localStorage.setItem("user", JSON.stringify(user));
    return user;
  } else {
    throw new Error("User not found");
  }
};

export const getCurrentUser = () => {
  const user = localStorage.getItem("user");
  return user ? JSON.parse(user) : null;
};

export const logout = () => {
  localStorage.removeItem("user");
  window.location.replace('/');
  return;
};
