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

ghost picture ghost  ·  3Comments

suifan picture suifan  ·  3Comments

happier2 picture happier2  ·  3Comments

cheung1111 picture cheung1111  ·  3Comments

952425340 picture 952425340  ·  3Comments