 
   db.get "SELECT value FROM metadata WHERE key = $key", {$key: key}, (err, row) ->
     if err then return cb "Couldn't get metadata for team #{team}: #{err}"
-    return cb null, row[0]
+    return cb null, row.value
 
 setMetaData = (team, key, value, cb) ->
   db = getDatabase team

    return done params?.error or "Failed to get any data from oauth"
  team = params.team_id
  async.series [
    (cb) -> setMetaData team, 'teamName', params.team, cb
    (cb) -> setMetaData team, 'teamId', params.team_id, cb
    (cb) -> setMetaData team, 'adminUserId', params.user_id, cb
    (cb) -> setMetaData team, 'botUserId', params.bot.bot_user_id, cb
    (cb) -> setMetaData team, 'token', params.bot.bot_access_token, cb
  ], (err) ->
    done err, params

app.use passport.initialize()


app = express()

# AUTH --------------------------------------------------------------------------

passport.use new SlackStrategy {
  clientID: process.env.SLACK_CLIENT_ID
  clientSecret: process.env.SLACK_CLIENT_SECRET
