import * as api from '@/api/api.js'
import { encryptionLogin } from '../util/Login.js'
let promise

export async function refreshToken() {
  if (promise) {
    return promise
  }
  promise = new Promise(async (resolve) => {
    const loginFrom = encryptionLogin()
    let res = await api.login(loginFrom, { __isRefreshToken: true })
    localStorage.setItem('mudu_token', res.access_token) //存token
    resolve(res.code === 200)
  })
  promise.finally(() => {
    promise = null
  })
  return promise
}

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