Picking up meteor.js user logout

前端 未结 6 2023
陌清茗
陌清茗 2020-12-30 01:52

Is there any way to pick up when a user logs out of the website? I need to do some clean up when they do so. Using the built-in meteor.js user accounts.

I\'ll be doi

6条回答
  •  不思量自难忘°
    2020-12-30 02:09

    Use the user-status package that I've created: https://github.com/mizzao/meteor-user-status. This is completely server-side.

    See the docs for usage, but you can attach an event handler to a session logout:

    UserStatus.events.on "connectionLogout", (fields) ->
      console.log(fields.userId + " with connection " + fields.connectionId + " logged out")
    

    Note that a user can be logged in from different places at once with multiple sessions. This smart package detects all of them as well as whether the user is online at all. For more information or to implement your own method, check out the code.

    Currently the package doesn't distinguish between browser window closes and logouts, and treats them as the same.

提交回复
热议问题