auth.js 441 B

1234567891011121314151617
  1. module.exports = async function () {
  2. if (this.authInfo) { // 多次执行auth时如果第一次成功后续不再执行
  3. return
  4. }
  5. const token = this.getUniIdToken()
  6. const payload = await this.uniIdCommon.checkToken(token)
  7. if (payload.errCode) {
  8. throw payload
  9. }
  10. this.authInfo = payload
  11. if (payload.token) {
  12. this.response.newToken = {
  13. token: payload.token,
  14. tokenExpired: payload.tokenExpired
  15. }
  16. }
  17. }