Adds medusa-plugin-permissions (#12)

This commit is contained in:
Oliver Windall Juhl
2020-04-06 15:57:31 +02:00
committed by GitHub
parent bc5dc5fab4
commit f6d5180e5f
13 changed files with 667 additions and 2 deletions
@@ -0,0 +1,14 @@
// This middleware is injected to ensure authorization of requests
// Since this middleware uses the user object on the request, this should be
// injected after authentication in the core middleware, hence we name
// the middleware postAuth.
export default postAuth = () => {
return (err, req, res, next) => {
const permissionService = req.scope.resolve("permissionService")
if (permissionService.hasPermission(req.user, req.method, req.path)) {
next()
} else {
res.status(422)
}
}
}