Spaces:
Running
Running
File size: 691 Bytes
9cd6ddb |
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 |
import { create } from "apisauce";
export const api = create({
baseURL: "/api",
});
export const MY_TOKEN_KEY = "discotools_token_key";
// set header authorization globally with localStorage token
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"),
};
|