import axios from "axios"; import axiosJWT from "../config/axios"; import qs from "qs"; export const login = async (username, password) => { try { const data = qs.stringify({ username, password, }); const response = await axios.post("http://localhost:5000/login", data, { headers: { "Content-Type": "application/x-www-form-urlencoded", }, withCredentials: true, }); return response.data; } catch (error) { if (error.response) return error.response.data; } }; export const refreshToken = async () => { try { const response = await axios.get("http://localhost:5000/token", { withCredentials: true }); return response.data; } catch (error) { if (error.response) return error.response.data; } }; export const getUser = async () => { try { const response = await axiosJWT.get("http://localhost:5000/user"); return response.data; } catch (error) { if (error.response) return error.response.data; } }; export const logout = async () => { try { const response = await axios.delete("http://localhost:5000/logout", { withCredentials: true, }); return response.data; } catch (error) { if (error.response) return error.response.data; } };