```coffeescript
Template.login.events
  'submit form': (e) ->
    e.preventDefault()
    user = e.target.username.value
    pass = e.target.password.value
    Meteor.loginWithPg user, pass, (err) ->
      unless err
        Tracker.autorun ->
          Meteor.call 'listFiles', Meteor.user().user
      else
        FlashMessages.sendError("Login failed: #{err.message}")
    false

Template.body.helpers
  loggedIn: ->
    if Meteor.user()
      Tracker.autorun ->
        Meteor.subscribe 'file-list', Meteor.user().user

Template.body.events
  'click #logout': (e) ->
    e.preventDefault()
    Meteor.logout()
```

Make sure there actually is a user when we list files
user
```coffeescript
Template.login.events
  'submit form': (e) ->
    e.preventDefault()
    user = e.target.username.value
    pass = e.target.password.value
    Meteor.loginWithPg user, pass, (err) ->
      unless err
        Tracker.autorun ->
          if user = Meteor.user()
            Meteor.call 'listFiles', user.user
      else
        FlashMessages.sendError("Login failed: #{err.message}")
    false

Template.body.helpers
  loggedIn: ->
    if Meteor.user()
      Tracker.autorun ->
        Meteor.subscribe 'file-list', Meteor.user().user

Template.body.events
  'click #logout': (e) ->
    e.preventDefault()
    Meteor.logout()
```
assistant