Skip to content
Snippets Groups Projects
Commit 877f428e authored by Yannis Barlas's avatar Yannis Barlas
Browse files

fix(middleware): permissions circular dependency

parent 1aac7069
No related branches found
No related tags found
2 merge requests!52Docx,!17Graphql api
......@@ -9,7 +9,20 @@ const {
not,
} = require('graphql-shield')
const { isAdmin, isAuthenticated } = require('./src/helpers')
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 = {
rule,
......
// const axios = require('axios')
const { rule } = require('graphql-shield')
const path = require('path')
const sharp = require('sharp')
const fs = require('fs-extra')
......@@ -10,21 +9,6 @@ const fs = require('fs-extra')
// const services = config.get('services')
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
},
)
const convertFileStreamIntoBuffer = async fileStream => {
return new Promise((resolve, reject) => {
// Store file data chunks
......@@ -172,8 +156,6 @@ const writeFileFromStream = async (inputStream, filePath) => {
// }
module.exports = {
isAuthenticated,
isAdmin,
convertFileStreamIntoBuffer,
getFileExtension,
getImageFileMetadata,
......
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