refreshToken.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const { Random } = require('mockjs')
  2. module.exports = [
  3. {
  4. url: '/expireToken',
  5. type: 'get',
  6. response: (config) => {
  7. const authorization =
  8. config.headers.authorization || config.headers.Authorization
  9. const arr = authorization.split('-')
  10. const tokenTime = parseInt(arr[arr.length - 1])
  11. if (new Date().getTime() - tokenTime > 5000)
  12. return {
  13. code: 402,
  14. msg: '令牌已过期',
  15. }
  16. else
  17. return {
  18. code: 200,
  19. msg: '令牌未过期',
  20. }
  21. },
  22. },
  23. {
  24. url: '/refreshToken',
  25. type: 'get',
  26. response: (config) => {
  27. const authorization =
  28. config.headers.authorization || config.headers.Authorization
  29. let token = ''
  30. if (authorization.includes('admin-token'))
  31. token = `admin-token-${Random.guid()}-${new Date().getTime()}`
  32. if (authorization.includes('editor-token'))
  33. token = `editor-token-${Random.guid()}-${new Date().getTime()}`
  34. if (authorization.includes('test-token'))
  35. token = `test-token-${Random.guid()}-${new Date().getTime()}`
  36. return {
  37. code: 200,
  38. msg: '刷新Token成功',
  39. data: { token },
  40. }
  41. },
  42. },
  43. ]