修复crsf问题
This commit is contained in:
6516
pnpm-lock.yaml
generated
Normal file
6516
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
4
src/lib/http/csrf.ts
Normal file
4
src/lib/http/csrf.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export const getCsrfToken = (): string | null => {
|
||||
const match = document.cookie.match(/(?:^|; )XSRF-TOKEN=([^;]*)/);
|
||||
return match ? decodeURIComponent(match[1]) : null;
|
||||
};
|
||||
@@ -2,6 +2,7 @@ import { useUserStore } from "@/stores/user";
|
||||
import type { AxiosInstance, InternalAxiosRequestConfig } from "axios";
|
||||
import { toast } from "sonner";
|
||||
import router from "@/router";
|
||||
import { getCsrfToken } from "./csrf";
|
||||
|
||||
export const downloadFile = (res: any) => {
|
||||
const [, filename] = res.headers["content-disposition"]?.split(";");
|
||||
@@ -26,11 +27,13 @@ export const setupInterceptors = (instance: AxiosInstance) => {
|
||||
"background:#4f46e5;color:#fff;",
|
||||
config,
|
||||
);
|
||||
const csrfToken = getCsrfToken();
|
||||
// @ts-ignore
|
||||
config.headers = {
|
||||
...config.headers,
|
||||
// @ts-ignore
|
||||
Authorization: `Bearer ${useUserStore.getState().token}`,
|
||||
"X-XSRF-TOKEN": csrfToken || "",
|
||||
};
|
||||
return config;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user