Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import axios from 'axios'
|
||||
import qs from 'qs'
|
||||
import { useAuthStore } from 'stores/authStore'
|
||||
import { DEFAULT_LOCALE, normalizeLocale } from 'src/i18n/languages'
|
||||
|
||||
const rawBaseUrl =
|
||||
(typeof process !== 'undefined' && process.env?.VITE_API_BASE_URL) || '/api'
|
||||
|
||||
export const API_BASE_URL = String(rawBaseUrl).trim().replace(/\/+$/, '')
|
||||
const AUTH_REFRESH_PATH = '/auth/refresh'
|
||||
const LOCALE_STORAGE_KEY = 'bss.locale'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
@@ -74,6 +76,11 @@ function redirectToLogin() {
|
||||
window.location.hash = '/login'
|
||||
}
|
||||
|
||||
function getRequestLocale() {
|
||||
if (typeof window === 'undefined') return DEFAULT_LOCALE
|
||||
return normalizeLocale(window.localStorage.getItem(LOCALE_STORAGE_KEY))
|
||||
}
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
const auth = useAuthStore()
|
||||
const url = config.url || ''
|
||||
@@ -82,6 +89,8 @@ api.interceptors.request.use((config) => {
|
||||
config.headers ||= {}
|
||||
config.headers.Authorization = `Bearer ${auth.token}`
|
||||
}
|
||||
config.headers ||= {}
|
||||
config.headers['Accept-Language'] = getRequestLocale()
|
||||
|
||||
return config
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user