auth.js 568 B

123456789101112131415161718192021
  1. async function existsUser(userCode){
  2. const response = await fetch("/api/existsUser", {
  3. method: "POST",
  4. headers: {
  5. "Content-Type": "application/json",
  6. "X-App-Token": chatToken
  7. },
  8. body: JSON.stringify({
  9. user_code: userCode
  10. })
  11. });
  12. if (!response.ok) {
  13. const errorData = await response.json().catch(() => ({ message: "Respuesta no válida del servidor." }));
  14. throw new Error(errorData.message || `Error del servidor: ${response.status}`);
  15. }
  16. const data = await response.json();
  17. return data;
  18. }
  19. export { existsUser};