refactor: 抽离管理后台基础设施模块
This commit is contained in:
1 parent
cfa183015b
commit
d811478d0f
3 files changed
+26
-21
No files matched your search
+2
-16
@@ -25,7 +25,7 @@ import {
|
||||
Modal,
|
||||
Badge,
|
||||
} from "antd";
|
||||
import { ApiClient } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "./lib/api.js";
|
||||
import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
|
||||
import type {
|
||||
BrandProfile,
|
||||
@@ -35,22 +35,8 @@ import type {
|
||||
} from "@personal-brand/api-client";
|
||||
import "antd/dist/reset.css";
|
||||
|
||||
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:3001";
|
||||
const queryClient = new QueryClient();
|
||||
async function authenticatedFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
||||
const response = await fetch(input, init);
|
||||
if (response.status === 401) {
|
||||
localStorage.removeItem("adminToken");
|
||||
window.dispatchEvent(new Event("admin-auth-expired"));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
const api = () =>
|
||||
new ApiClient({
|
||||
baseUrl: apiBaseUrl,
|
||||
token: localStorage.getItem("adminToken") ?? undefined,
|
||||
fetcher: authenticatedFetch,
|
||||
});
|
||||
const api = createApiClient;
|
||||
|
||||
function Login({ onLogin }: { onLogin: () => void }) {
|
||||
const [form] = Form.useForm();
|
||||
|
||||
Reference in new issue
Block a user