Ocelot-Social/src/middleware/permissionsMiddleware.js
Robert Schäfer 69bf53e05e Impplement currentUser query
* remove dead code (passport-jwt)
* refactor resolves to have a separate folder
* currentUser and login have the same response
2019-02-26 16:35:31 +01:00

47 lines
1.1 KiB
JavaScript

import { rule, shield, allow } from 'graphql-shield'
/*
* TODO: implement
* See: https://github.com/Human-Connection/Nitro-Backend/pull/40#pullrequestreview-180898363
*/
const isAuthenticated = rule()(async (parent, args, ctx, info) => {
return ctx.user !== null
})
/*
const isAdmin = rule()(async (parent, args, ctx, info) => {
return ctx.user.role === 'ADMIN'
})
const isModerator = rule()(async (parent, args, ctx, info) => {
return ctx.user.role === 'MODERATOR'
})
*/
const isMyOwn = rule({ cache: 'no_cache' })(async (parent, args, ctx, info) => {
return ctx.user.id === parent.id
})
// Permissions
const permissions = shield({
Query: {
statistics: allow,
currentUser: allow
// fruits: and(isAuthenticated, or(isAdmin, isModerator)),
// customers: and(isAuthenticated, isAdmin)
},
Mutation: {
CreatePost: isAuthenticated,
// TODO UpdatePost: isOwner,
// TODO DeletePost: isOwner,
report: isAuthenticated
// addFruitToBasket: isAuthenticated
// CreateUser: allow,
},
User: {
email: isMyOwn,
password: isMyOwn
}
// Post: isAuthenticated
})
export default permissions