feat: add admin auth middleware

This commit is contained in:
yanghao05
2025-04-16 20:26:02 +08:00
parent 4a9836db68
commit 92a070cc81
5 changed files with 34 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
import { useAuthStore } from '@/stores/auth';
import axios from 'axios';
// Create axios instance with default config
@@ -12,11 +13,10 @@ const httpClient = axios.create({
// Request interceptor
httpClient.interceptors.request.use(
config => {
// You can add auth token here if needed
// const token = localStorage.getItem('token');
// if (token) {
// config.headers.Authorization = `Bearer ${token}`;
// }
const authStore = useAuthStore();
if (authStore.isAuthenticated && authStore.token) {
config.headers.Authorization = `Bearer ${authStore.token}`;
}
return config;
},
error => {