Determine whether the token expires before the axios request. If it expires, request the token before sending the request.

1. When you encounter a problem with the expiration of token, enter the system to determine whether there is a token,. If not, request token first.

2. Determine whether the token expires before other subsequent requests are sent, and if so, re-request the token, and then send the request.

3. Dear gods, is there a good plan to intercept with axios? please answer, thank you!

Mar.11,2021

this is undoubtedly the best choice to use fly.js, which is basically the same as axios. Fly.js can check token, for asynchronous tasks in the request interceptor. For more information, please see fly.js

.
var csrfToken="";
var tokenFly=new Fly();
var fly=new Fly();
fly.interceptors.request.use(function (request) {
  log(`:path:${request.url}baseURL:${request.baseURL}`)
  if (!csrfToken) {
    log("tokentoken...");
    //
    fly.lock();
    return newFly.get("/token").then((d) => {
      request.headers["csrfToken"] = csrfToken = d.data.data.token;
      log("token: " + d.data.data.token);
      log(`:path:${request.url}baseURL:${request.baseURL}`)
      return request; //request
    }).finally(()=>{
      fly.unlock();//
    })
  } else {
    request.headers["csrfToken"] = csrfToken;
  }
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3aed7-3461d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3aed7-3461d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?