CoolFace
Apppublic

Humeid/deepsite

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
api.ts36 linesDownload Raw Back to lib
1import axios from "axios";2import MY_TOKEN_KEY from "./get-cookie-name";3 4export const api = axios.create({5  baseURL: `/api`,6  headers: {7    cache: "no-store",8  },9});10 11export const apiServer = axios.create({12  baseURL: process.env.NEXT_APP_API_URL as string,13  headers: {14    cache: "no-store",15  },16});17 18api.interceptors.request.use(19  async (config) => {20    // get the token from cookies21    const cookie_name = MY_TOKEN_KEY();22    const token = document.cookie23      .split("; ")24      .find((row) => row.startsWith(`${cookie_name}=`))25      ?.split("=")[1];26    if (token) {27      config.headers.Authorization = `Bearer ${token}`;28    }29    return config;30  },31  (error) => {32    // Handle the error33    return Promise.reject(error);34  }35);36