Browse Source

feat(xsrf): Add `xsrf-token` in the request header

pull/1325/head
colin 7 months ago
parent
commit
99a185465f
  1. 3
      apps/vben5/apps/app-antd/src/adapter/request/index.ts
  2. 9
      apps/vben5/packages/@abp/core/src/store/abp.ts

3
apps/vben5/apps/app-antd/src/adapter/request/index.ts

@ -61,6 +61,9 @@ export function initRequestClient() {
if (abpStore.tenantId) { if (abpStore.tenantId) {
config.headers.__tenant = abpStore.tenantId; config.headers.__tenant = abpStore.tenantId;
} }
if (abpStore.xsrfToken) {
config.headers.RequestVerificationToken = abpStore.xsrfToken;
}
return config; return config;
}, },
}); });

9
apps/vben5/packages/@abp/core/src/store/abp.ts

@ -6,11 +6,17 @@ import type {
import { ref } from 'vue'; import { ref } from 'vue';
import { acceptHMRUpdate, defineStore } from 'pinia'; import { acceptHMRUpdate, defineStore } from 'pinia';
import Cookies from 'universal-cookie';
export const useAbpStore = defineStore( export const useAbpStore = defineStore(
'abp', 'abp',
() => { () => {
const cookies = new Cookies(null, {
domain: window.location.host,
path: '/',
});
const tenantId = ref<string>(); const tenantId = ref<string>();
const xsrfToken = ref<string>();
const application = ref<ApplicationConfigurationDto>(); const application = ref<ApplicationConfigurationDto>();
const localization = ref<ApplicationLocalizationDto>(); const localization = ref<ApplicationLocalizationDto>();
/** 获取 i18n 格式本地化文本 */ /** 获取 i18n 格式本地化文本 */
@ -52,6 +58,7 @@ export const useAbpStore = defineStore(
function setApplication(val: ApplicationConfigurationDto) { function setApplication(val: ApplicationConfigurationDto) {
application.value = val; application.value = val;
xsrfToken.value = cookies.get('XSRF-TOKEN');
} }
function setLocalization(val: ApplicationLocalizationDto) { function setLocalization(val: ApplicationLocalizationDto) {
@ -59,12 +66,14 @@ export const useAbpStore = defineStore(
} }
function $reset() { function $reset() {
xsrfToken.value = undefined;
application.value = undefined; application.value = undefined;
} }
return { return {
$reset, $reset,
application, application,
xsrfToken,
getI18nLocales, getI18nLocales,
localization, localization,
setApplication, setApplication,

Loading…
Cancel
Save