|
|
@@ -9,7 +9,7 @@ import 'dayjs/locale/zh-cn';
|
|
|
import type {
|
|
|
AuthContextType
|
|
|
} from '@d8d/shared-types';
|
|
|
-import { authClient } from '../api/authClient';
|
|
|
+import { authClient , authClientManager} from '../api/authClient';
|
|
|
import type { InferResponseType } from 'hono/client';
|
|
|
|
|
|
type User = InferResponseType<typeof authClient.me.$get, 200>;
|
|
|
@@ -36,7 +36,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|
|
try {
|
|
|
// 如果已登录,调用登出API
|
|
|
if (token) {
|
|
|
- await authClient.logout.$post();
|
|
|
+ await authClientManager.get().logout.$post();
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('登出请求失败:', error);
|
|
|
@@ -68,7 +68,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|
|
// 设置全局默认请求头
|
|
|
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
|
|
// 使用API验证当前用户
|
|
|
- const res = await authClient.me.$get();
|
|
|
+ const res = await authClientManager.get().me.$get();
|
|
|
if (res.status !== 200) {
|
|
|
const result = await res.json();
|
|
|
throw new Error(result.message)
|
|
|
@@ -104,7 +104,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|
|
}
|
|
|
|
|
|
// 使用AuthAPI登录
|
|
|
- const response = await authClient.login.$post(requestParams)
|
|
|
+ const response = await authClientManager.get().login.$post(requestParams)
|
|
|
if (response.status !== 200) {
|
|
|
const result = await response.json()
|
|
|
throw new Error(result.message);
|