import { loginMudu2 } from '@/api/mudu/records.js'

let promise

export async function refreshToken() {
  if (promise) {
    return promise
  }
  promise = new Promise(async (resolve) => {
    const loginFrom = {
      username: 'admin',
      password: 'Mudu@123.',
    }
    let res = await loginMudu2(loginFrom, { __isRefreshToken: true })
    localStorage.setItem('mudu2_token', res.token) //存token
    resolve(res.code === 200)
  })
  promise.finally(() => {
    promise = null
  })
  return promise
}

export function isRefreshRequest(config) {
  // console.log(config.__isRefreshToken)
  return !!config.__isRefreshToken //两个取反，变成boolean
}
