logout.js 763 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const {
  2. dbCmd,
  3. LOG_TYPE,
  4. deviceCollection,
  5. userCollection
  6. } = require('../../common/constants')
  7. async function logout() {
  8. const {
  9. uniIdToken,
  10. deviceId
  11. } = this.getClientInfo()
  12. const {
  13. uid
  14. } = await this.uniIdCommon.checkToken(
  15. uniIdToken,
  16. {
  17. autoRefresh: false
  18. }
  19. )
  20. // 删除token
  21. await userCollection.doc(uid).update({
  22. token: dbCmd.pull(uniIdToken)
  23. })
  24. // 仅当device表的device_id和user_id均对应时才进行更新
  25. await deviceCollection.where({
  26. device_id: deviceId,
  27. user_id: uid
  28. }).update({
  29. token_expired: 0
  30. })
  31. await this.middleware.uniIdLog({
  32. data: {
  33. user_id: uid
  34. },
  35. type: LOG_TYPE.LOGOUT
  36. })
  37. return {
  38. errCode: 0
  39. }
  40. }
  41. module.exports = {
  42. logout
  43. }