garrettmills
9df5f2d5f4
All checks were successful
continuous-integration/drone/push Build is passing
26 lines
740 B
JavaScript
26 lines
740 B
JavaScript
const { Middleware } = require('libflitter')
|
|
|
|
class ApiRoute extends Middleware {
|
|
static get services() {
|
|
return [...super.services, 'models']
|
|
}
|
|
|
|
async test(req, res, next, { allow_public = false }) {
|
|
console.log({allow_public})
|
|
// If we have an authenticated session, just continue
|
|
if ( req.is_auth ) {
|
|
return next()
|
|
} else if ( allow_public ) {
|
|
const PublicUser = this.models.get('auth:PublicUser')
|
|
req.user = await PublicUser.get_for_request(req)
|
|
return next()
|
|
} else {
|
|
return res.status(401)
|
|
.message('API authentication required')
|
|
.api()
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = ApiRoute
|