fix(csrfToken): 更新CsrfToken的获取方式,改为从Cookie中获取

This commit is contained in:
OrangeM21
2020-08-19 17:25:34 +08:00
committed by 老广
parent 2832d876fd
commit 93dba0bbee

View File

@@ -1,6 +1,6 @@
import axios from 'axios' import axios from 'axios'
import i18n from '@/i18n/i18n' import i18n from '@/i18n/i18n'
import { getTokenFromCookie } from '@/utils/auth'
import { Message, MessageBox } from 'element-ui' import { Message, MessageBox } from 'element-ui'
import store from '@/store' import store from '@/store'
@@ -12,11 +12,12 @@ const service = axios.create({
}) })
function beforeRequestAddToken(config) { function beforeRequestAddToken(config) {
if (store.getters.token) { const csrfToken = getTokenFromCookie()
if (csrfToken) {
// let each request carry token // let each request carry token
// ['X-Token'] is a custom headers key // ['X-Token'] is a custom headers key
// please modify it according to the actual situation // please modify it according to the actual situation
config.headers['X-CSRFToken'] = store.getters.token config.headers['X-CSRFToken'] = csrfToken
} }
if (store.getters.currentOrg) { if (store.getters.currentOrg) {
config.headers['X-JMS-ORG'] = store.getters.currentOrg.id config.headers['X-JMS-ORG'] = store.getters.currentOrg.id