first commit
This commit is contained in:
1 parent
b27f4f2f23
commit
db10146ecd
58 files changed
+3684
-202
No files matched your search
@@ -0,0 +1,41 @@
|
||||
'use client'
|
||||
|
||||
import axios from 'axios'
|
||||
import { error } from 'console';
|
||||
import { cookies, headers } from 'next/headers'
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: 'http://localhost:3000/api/',
|
||||
timeout: 2000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
});
|
||||
|
||||
axiosInstance.interceptors.response.use((response)=> {
|
||||
return response
|
||||
}, async (error) =>{
|
||||
|
||||
const originalRequest = error.config;
|
||||
|
||||
if (error.response.status === 401 && !originalRequest._retry) {
|
||||
|
||||
originalRequest._retry = true; // Prevent infinite loops
|
||||
|
||||
try {
|
||||
|
||||
const res = await fetch("http://localhost:3000/api/auth/token/refresh/",{
|
||||
method: "GET",
|
||||
cache: "no-store",
|
||||
});
|
||||
console.log(res);
|
||||
|
||||
return axiosInstance(originalRequest)
|
||||
|
||||
} catch(refreshError) {
|
||||
throw refreshError;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default axiosInstance
|
||||
Reference in new issue
Block a user