       .child user.uid
 
   onUserLogout: ->
-    @userRef?.off 'value'
-    @userStore.onLogout !!@userRef
+    userWasLogged = !!@userRef
+    @userRef.off 'value' if userWasLogged
+    @userRef = null
+    ###*
+      PATTERN: Logout has to delete all data in memory and in localStorage, but
+      only if user was logged before. We don't want to delete data for not yet
+      registered/logged user.
+    ###
+    @userStore.clearOnLogout userWasLogged
+    @userStore.serverNotify()
 
   loginViaFacebook: ->
     @authClient.login 'facebook',


  logout: ->
    @authClient.logout()

  onUserLogin: (user) ->
    @userRef = @userRefOf user
    userJustLogged = true
    @userRef.on 'value',
      (snap) =>
        # Ignore local changes, workaround for Firebase behavior.
        return if @isLocalChange_
        # Can be null for new users.
        val = snap.val()
        # Merge server changes to client.
        @userStore.updateFromServer user, val
        if userJustLogged
          userJustLogged = false
          # Sync with saving to server to preserve local changes.
          @userStore.notify()
        else
          # Only local sync.
          @userStore.serverNotify()
    , (error) ->
      # TODO: Report to server.
      if goog.DEBUG
