logout.js 821 字节
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3 4 5 6 7
const {
  dbCmd,
  LOG_TYPE,
  deviceCollection,
  userCollection
} = require('../../common/constants')

study夏羽's avatar
study夏羽 已提交
8
async function logout () {
DCloud_JSON's avatar
DCloud_JSON 已提交
9 10 11
  const {
    uniIdToken,
    deviceId
study夏羽's avatar
study夏羽 已提交
12
  } = this.getUniversalClientInfo()
DCloud_JSON's avatar
DCloud_JSON 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
  const {
    uid
  } = await this.uniIdCommon.checkToken(
    uniIdToken,
    {
      autoRefresh: false
    }
  )

  // 删除token
  await userCollection.doc(uid).update({
    token: dbCmd.pull(uniIdToken)
  })

  // 仅当device表的device_id和user_id均对应时才进行更新
  await deviceCollection.where({
    device_id: deviceId,
    user_id: uid
  }).update({
    token_expired: 0
  })
  await this.middleware.uniIdLog({
    data: {
      user_id: uid
    },
    type: LOG_TYPE.LOGOUT
  })
  return {
    errCode: 0
  }
}

module.exports = {
  logout
study夏羽's avatar
study夏羽 已提交
47
}