Browse Source

Merge pull request #1325 from colinin/vben5-xsrf-token

feat(xsrf): Add `xsrf-token` in the request header
pull/1327/head
yx lin 5 months ago
committed by GitHub
parent
commit
f91f3c6924
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  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) {
config.headers.__tenant = abpStore.tenantId;
}
if (abpStore.xsrfToken) {
config.headers.RequestVerificationToken = abpStore.xsrfToken;
}
return config;
},
});

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

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

Loading…
Cancel
Save