diff --git a/index.html b/index.html
index 86a3c58..b560476 100644
--- a/index.html
+++ b/index.html
@@ -3,7 +3,7 @@
- AI 智能体管理平台
+ 驷马智能
diff --git a/src/api.ts b/src/api.ts
index fdc6602..72aba84 100644
--- a/src/api.ts
+++ b/src/api.ts
@@ -1,6 +1,7 @@
import axios from 'axios';
const AURA_API_BASE = 'https://api.redhare.cc/aura/v1';
+const isMockAuth = () => typeof localStorage !== 'undefined' && localStorage.getItem('mock-auth') === '1';
export const api = axios.create({
baseURL: '/api',
@@ -12,7 +13,7 @@ export const api = axios.create({
api.interceptors.response.use(
(r) => r,
(err) => {
- if (err?.response?.status === 401 && !location.pathname.startsWith('/login')) {
+ if (err?.response?.status === 401 && !location.pathname.startsWith('/login') && !isMockAuth()) {
const next = encodeURIComponent(location.pathname + location.search);
location.href = `/login?next=${next}`;
}
diff --git a/src/store/auth.ts b/src/store/auth.ts
index e89e53c..92c71ea 100644
--- a/src/store/auth.ts
+++ b/src/store/auth.ts
@@ -11,8 +11,18 @@ interface AuthState {
logout: () => Promise;
}
+const loadSavedUser = (): AuthUser | null => {
+ try {
+ const raw = localStorage.getItem('mock-user');
+ if (!raw) return null;
+ return JSON.parse(raw) as AuthUser;
+ } catch {
+ return null;
+ }
+};
+
export const useAuth = create((set) => ({
- user: null,
+ user: typeof localStorage === 'undefined' ? null : loadSavedUser(),
loading: false,
bootstrap: async () => {
set({ loading: false });
@@ -20,14 +30,18 @@ export const useAuth = create((set) => ({
login: async (email, password) => {
const ok = await AuthAPI.verify(email, password);
if (!ok) throw new Error('身份验证失败');
- set({
- user: {
- id: 'mock',
- email,
- name: email.split('@')[0] || 'User',
- role: 'user'
- }
- });
+ const u: AuthUser = {
+ id: 'mock',
+ email,
+ name: email.split('@')[0] || 'User',
+ role: 'user'
+ };
+ try {
+ localStorage.setItem('mock-auth', '1');
+ localStorage.setItem('mock-user', JSON.stringify(u));
+ } catch {
+ }
+ set({ user: u });
},
register: async (p) => {
const u = await AuthAPI.register(p);
@@ -38,6 +52,11 @@ export const useAuth = create((set) => ({
await AuthAPI.logout();
} catch {
}
+ try {
+ localStorage.removeItem('mock-auth');
+ localStorage.removeItem('mock-user');
+ } catch {
+ }
set({ user: null });
}
}));