Adds Middleware API (#40)
* Adds test project * Adds e2e for end-2-end tests * Update gitignore * Update loaders * Creates test project * v0.1.27 * Upgrade * dependency fixes * Load project plugins in the plugin loader * Issue with instanceof * Fixes versioning issues * Adds medusa middleware api * Adds documentation * Fixes tests
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// 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 {
|
||||
postAuthentication: () => {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user