         { clientIP } = session
         callback {
           sessionToken, context, clientIP,
-          connection:delegate:account
+          connection:{ delegate : account }
         }
 
       else
-        console.error "this is not a proper account", {sessionToken}
-        console.error "constructor is JAccount", JAccount is account.constructor
+        console.error 'this is not a proper account', { sessionToken }
+        console.error 'constructor is JAccount', JAccount is account.constructor
 }
 
-koding.on 'authenticateUser', (client, callback)->
-  {delegate} = client.connection
+koding.on 'authenticateUser', (client, callback) ->
+  { delegate } = client.connection
   callback delegate
 
-koding.on "errFirstDetected", (err)-> console.error err
+koding.on 'errFirstDetected', (err) -> console.error err
 
 koding.connect ->
   (require './init').init koding

Broker = require 'broker'

KONFIG = require('koding-config-manager').load("main.#{argv.c}")
Object.defineProperty global, 'KONFIG', value: KONFIG
{mq, email, social, mongoReplSet, socialapi} = KONFIG

mongo = "mongodb://#{KONFIG.mongo}"  if 'string' is typeof KONFIG.mongo


    fetchClient: (name, context, callback) ->
      { JAccount } = koding.models
      [callback, context] = [context, callback] unless callback
      context   ?= { group: 'koding' }
      callback  ?= ->
      JAccount.one { 'profile.nickname': name }, (err, account) ->
        return callback err  if err?

        if account instanceof JAccount
          callback null, { context, connection: { delegate : account } }

  fetchClient: (sessionToken, context, callback) ->

    { JUser, JAccount } = koding.models
    [callback, context] = [context, callback] unless callback
    callback            ?= ->

    JUser.authenticateClient sessionToken, (err, res = {}) ->

      { account, session } = res

      context ?= { group: session?.groupName ? 'koding' }

      if err
        console.error 'bongo.fetchClient', { err, sessionToken, context }
        koding.emit 'error', err

      else if account instanceof JAccount
