You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
689 B

const { Middleware } = require('libflitter')
/*
* InjectUserTeam Middleware
* -------------------------------------------------------------
* For the authenticated user, looks up the associated Team instance
* and injects it as request.team.
*/
class InjectUserTeam extends Middleware {
static get services() {
return [...super.services, 'models']
}
/*
* Run the middleware test.
*/
async test(req, res, next, args = {}){
if ( !req.user ) return res.redirect('/auth/login')
const Team = this.models.get('Team')
req.user_team = await Team.getForUser(req.user)
return next()
}
}
module.exports = InjectUserTeam