 #
 serializeUser = (user, done) ->
   user.fetch
+    data:
+      auth_token: user.get('access_token')
     success: ->
-      keys = ['accessToken'].concat opts.userKeys
+      keys = ['access_token'].concat opts.userKeys
       done null, user.pick(keys)
-    error: (m, e) -> done e.text
+    error: (m, e) ->
+      done e.text
 
 deserializeUser = (userData, done) ->
   done null, new opts.CurrentUser(userData)

  if req.user
    res.locals.user = req.user
    res.locals.sd?.CURRENT_USER = req.user.toJSON()
    res.locals.sd?.XAuthToken = req.user.get('authentication_token')
  next()

headerLogin = (req, res, next) ->
  if token = req.get('X-AUTH-TOKEN') or req.query.access_token
    req.login new opts.CurrentUser(accessToken: token), next
  else
    next()



# Default options
opts =
  SECURE_ARENA_URL: 'https://secure.are.na'
  loginPath: '/me/sign_in'
  signupPath: '/me/invitation/accept'
  userKeys: ['id', 'first_name', 'last_name', 'email', 'slug', 'following_ids', 'notification_count', 'username', 'authentication_token']
