|
|
import { create } from "apisauce"; |
|
|
|
|
|
export const api = create({ |
|
|
baseURL: "/api", |
|
|
}); |
|
|
|
|
|
export const MY_TOKEN_KEY = "discotools_token_key"; |
|
|
|
|
|
|
|
|
if (typeof window !== "undefined") { |
|
|
const token = localStorage.getItem(MY_TOKEN_KEY); |
|
|
if (token) { |
|
|
api.setHeader("Authorization", `Bearer ${token}`); |
|
|
} |
|
|
} |
|
|
|
|
|
api.addResponseTransform((response: any) => { |
|
|
if (!response.ok) throw response; |
|
|
}); |
|
|
|
|
|
export const API = { |
|
|
login: async () => await api.post("/auth"), |
|
|
me: async () => await api.get("/auth/@me"), |
|
|
download: async () => await api.post("/icons/create"), |
|
|
downloadBadge: async () => await api.post("/badges/create"), |
|
|
}; |
|
|
|