fix(frontend): auto-attach admin api keys and normalize admin list payloads
This commit is contained in:
@@ -2,6 +2,8 @@ import axios from 'axios'
|
||||
import router from '@/router'
|
||||
|
||||
const BASE_URL = import.meta.env.VITE_API_BASE_URL
|
||||
const ENV_ADMIN_CLIENT_KEY = import.meta.env.VITE_ADMIN_CLIENT_KEY
|
||||
const ENV_ADMIN_API_KEY = import.meta.env.VITE_ADMIN_API_KEY
|
||||
|
||||
// 使用者 API:帶 Bearer token
|
||||
export const userHttp = axios.create({ baseURL: BASE_URL })
|
||||
@@ -29,8 +31,14 @@ userHttp.interceptors.response.use(
|
||||
export const adminHttp = axios.create({ baseURL: BASE_URL })
|
||||
|
||||
adminHttp.interceptors.request.use(config => {
|
||||
const clientKey = sessionStorage.getItem('admin_client_key')
|
||||
const apiKey = sessionStorage.getItem('admin_api_key')
|
||||
const clientKey = sessionStorage.getItem('admin_client_key') || ENV_ADMIN_CLIENT_KEY
|
||||
const apiKey = sessionStorage.getItem('admin_api_key') || ENV_ADMIN_API_KEY
|
||||
if (clientKey && !sessionStorage.getItem('admin_client_key')) {
|
||||
sessionStorage.setItem('admin_client_key', clientKey)
|
||||
}
|
||||
if (apiKey && !sessionStorage.getItem('admin_api_key')) {
|
||||
sessionStorage.setItem('admin_api_key', apiKey)
|
||||
}
|
||||
if (clientKey) config.headers['X-Client-Key'] = clientKey
|
||||
if (apiKey) config.headers['X-API-Key'] = apiKey
|
||||
return config
|
||||
|
||||
Reference in New Issue
Block a user