   # Users
   assignUser: (data) ->
     return null unless data.user_id
-    @user = JSON.parse data.attributes  
+    @user = new UserSession(data.user_id, @)
+    @user.attributes = JSON.parse(data.attributes) if data.attributes
 
   loggedIn: ->
     @user?

utils = require('./utils')

class exports.Session
  

    @user = null
    @create (err, new_session) -> cb(null, new_session)    
  
  setUserAndAttributes: (user_id, user_data) ->
    return null if user_id is undefined or user_data is undefined
    R.hset @key(), 'user_id', user_id
    @assignUser(user_data)    
    R.hset @key(), 'attributes', JSON.stringify(Object.extend(@getAttributes(), user_data)) # Set attributes    
    
  getAttributes: ->
    attr = R.hget @key(), 'attributes'
    JSON.parse(attr || '{}')