first commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// axios-config.js
|
||||
import axios from "axios";
|
||||
import { getTokenFromLocalStorage } from "./token";
|
||||
|
||||
/*
|
||||
const instance = axios.create({
|
||||
baseURL: process.env.NEXT_PUBLIC_API_URL,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: getTokenFromLocalStorage(),
|
||||
},
|
||||
});*/
|
||||
|
||||
const instance = () =>
|
||||
axios.create({
|
||||
baseURL: process.env.NEXT_PUBLIC_API_URL,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: getTokenFromLocalStorage(),
|
||||
},
|
||||
});
|
||||
|
||||
export default instance;
|
||||
@@ -0,0 +1,22 @@
|
||||
"use client";
|
||||
export function getTokenFromLocalStorage(): string {
|
||||
if (typeof window !== "undefined") {
|
||||
if (!localStorage) {
|
||||
throw new Error("Local storage not found");
|
||||
}
|
||||
|
||||
// Get the stored data from local storage
|
||||
const storedData = localStorage.getItem("site-session-token");
|
||||
|
||||
// Parse the stored data as JSON
|
||||
const jsonData = storedData ? JSON.parse(storedData) : null;
|
||||
|
||||
// If jsonData is truthy, return the token value
|
||||
if (jsonData) {
|
||||
return jsonData.state.token;
|
||||
}
|
||||
}
|
||||
|
||||
// Return an empty string if no token is found
|
||||
return "";
|
||||
}
|
||||
Reference in New Issue
Block a user