Skip to content
Snippets Groups Projects
Commit f17b2655 authored by jgutix's avatar jgutix
Browse files

feat(middleware): add helpers for authorization middleware

parent 9773acd3
No related branches found
No related tags found
1 merge request!2feat(middleware): add helpers for authorization middleware
......@@ -9,6 +9,8 @@ const {
not,
} = require('graphql-shield')
const { isAdmin, isAuthenticated } = require('./src/helpers')
module.exports = {
rule,
inputRule,
......@@ -18,4 +20,6 @@ module.exports = {
chain,
or,
not,
isAuthenticated,
isAdmin,
}
const { rule } = require('graphql-shield')
const isAuthenticated = rule()(async (parent, args, ctx, info) => {
return !!ctx.user
})
const isAdmin = rule()(
async (parent, args, { user: userId, connectors: { User } }, info) => {
if (!userId) {
return false
}
const user = await User.model.findById(userId)
return user.admin
},
)
module.exports = {
isAuthenticated,
isAdmin,
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment