Amend CORS and NGINX
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
import axios from "axios";
|
||||
import {userManager} from "../stores/auth.ts";
|
||||
import {getConfig} from "@/util/config.ts";
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: getConfig().API_BASE_URL || '/api',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
axiosInstance.interceptors.request.use(async (config) => {
|
||||
const user = await userManager.getUser()
|
||||
if (user?.access_token) {
|
||||
config.headers.Authorization = `Bearer ${user.access_token}`
|
||||
}
|
||||
return config
|
||||
})
|
||||
|
||||
// Handle token expiration
|
||||
axiosInstance.interceptors.response.use(
|
||||
response => response,
|
||||
async (error) => {
|
||||
if (error.response?.status === 401) {
|
||||
await userManager.signinRedirect()
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default axiosInstance;
|
||||
Reference in New Issue
Block a user