Ant-design-pro: 求助,后端返回jwt,在request.js如何处理?

Created on 5 Jun 2018  ·  3Comments  ·  Source: ant-design/ant-design-pro

后端java返回的jwt在header里面,request.js如何提取token并保存呢?

screenshot

Most helpful comment

// request
const defaultOptions = {
  credentials: 'include',
  headers: {},
};
if (newOptions.method === 'POST' || newOptions.method === 'PUT') {
  // some code
}
const token = getToken();
if (token) {
  newOptions.headers.Authorization = `Bearer ${token}`;
}

// response
return fetch(url, newOptions)
  .then(checkStatus)
  .then(response => {
    const newToken = response.headers.get('authorization');
    if (newToken) setToken(newToken);

All 3 comments

Translation of this issue:


Help, back-end return jwt, how to deal with in request.js?

The jwt returned from the back end is inside the header. How does request.js extract the token and save it?

screenshot

// request
const defaultOptions = {
  credentials: 'include',
  headers: {},
};
if (newOptions.method === 'POST' || newOptions.method === 'PUT') {
  // some code
}
const token = getToken();
if (token) {
  newOptions.headers.Authorization = `Bearer ${token}`;
}

// response
return fetch(url, newOptions)
  .then(checkStatus)
  .then(response => {
    const newToken = response.headers.get('authorization');
    if (newToken) setToken(newToken);

请问v4 怎么处理

Was this page helpful?
0 / 5 - 0 ratings

Related issues

renyi818 picture renyi818  ·  3Comments

gaoqiang19514 picture gaoqiang19514  ·  3Comments

zhongjiewu picture zhongjiewu  ·  3Comments

yadongxie150 picture yadongxie150  ·  3Comments

skyFi picture skyFi  ·  3Comments