Created
August 9, 2016 18:05
-
-
Save selfcontained/4ed33a43168d1439f090cf989b84c36a to your computer and use it in GitHub Desktop.
Slapp Firebase context middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
// Slapp context middleware function | |
// Looks up team info from db and enriches request | |
module.exports = (db) => { | |
return (req, res, next) => { | |
let teamId = req.slapp.meta.team_id | |
db.getTeam(teamId, (err, team) => { | |
if (err) { | |
console.error(err) | |
return res.send(err) | |
} | |
req.slapp.meta = Object.assign(req.slapp.meta, { | |
app_token: team.access_token, | |
bot_token: team.bot.bot_access_token, | |
bot_user_id: team.bot.bot_user_id, | |
team_name: team.team_name | |
}) | |
next() | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment