File size: 908 Bytes
6c4e56e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import axios from "axios";
import { handleApiError } from "../lib/errorHandler";

const api = axios.create({
  baseURL: process.env.REACT_APP_API_URL || "",
});

api.interceptors.request.use(async (config) => {
  const token = await localStorage.getItem("messenger-token");
  config.headers["x-access-token"] = token;
  return config;
});

api.interceptors.response.use(
  (response) => response,
  (error) => {
    const errorMessage = handleApiError(error);
    return Promise.reject(errorMessage);
  }
);

export const authAPI = {
  login: (credentials) => api.post("/auth/login", credentials),
  register: (credentials) => api.post("/auth/register", credentials),
  logout: () => api.delete("/auth/logout"),
  getCurrentUser: () => api.get("/auth/user"),
};

export const onboardingAPI = {
  getSteps: () => api.get("/api/onboarding"),
  submitOnboarding: (data) => api.post("/api/onboarding", data),
};