feat: add local access control and managed point clouds
This commit is contained in:
@@ -4,8 +4,8 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { httpBatchLink, httpLink, splitLink, TRPCClientError } from "@trpc/client";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import superjson from "superjson";
|
||||
import { toast } from "sonner";
|
||||
import App from "./App";
|
||||
import { getLoginUrl } from "./const";
|
||||
import "./index.css";
|
||||
|
||||
// 禁用 HMR 失败时的自动页面刷新,保留热更新功能
|
||||
@@ -37,7 +37,7 @@ const redirectToLoginIfUnauthorized = (error: unknown) => {
|
||||
|
||||
if (!isUnauthorized) return;
|
||||
|
||||
window.location.href = getLoginUrl();
|
||||
if (window.location.pathname !== "/login") window.location.href = "/login";
|
||||
};
|
||||
|
||||
queryClient.getQueryCache().subscribe(event => {
|
||||
@@ -52,6 +52,9 @@ queryClient.getMutationCache().subscribe(event => {
|
||||
if (event.type === "updated" && event.action.type === "error") {
|
||||
const error = event.mutation.state.error;
|
||||
redirectToLoginIfUnauthorized(error);
|
||||
if (error instanceof TRPCClientError && error.data?.code === "FORBIDDEN") {
|
||||
toast.error(error.message || "无权执行此操作");
|
||||
}
|
||||
console.error("[API Mutation Error]", error);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user