-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
48 lines (46 loc) · 1.37 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { shield, rule, and, inputRule, deny, allow } from 'graphql-shield'
import { isAdminFromHeader } from '../utils/utils'
import { Context } from '../context'
const Rules = {
isAdmin: rule()((_parent, _args, context: Context) => {
const admin = isAdminFromHeader(context) || false
if(admin){
console.log(isAdminFromHeader(context))
return admin
}
return new Error("Not authorized please contact admin to allow access")
}),
signup : rule()((_parent, _args, context: Context) => {
return true
}),
// isPostOwner: rule()(async (_parent, args, context) => {
// const userId = getUserEmailWithRole(context)
// const author = await context.prisma.post
// .findUnique({
// where: {
// id: Number(args.id),
// },
// })
// .author()
// return userId === author.id
// }),
}
export const permissions = shield({
Query: {
'*': allow,
},
Mutation: {
'*': deny,
createOneCategory: Rules.isAdmin,
updateOneCategory: Rules.isAdmin,
// deleteOneCategory : Rules.isAdmin,
createOnesub_catagory: Rules.isAdmin,
updateOnesub_catagory: Rules.isAdmin,
// deleteOnesub_catagory : Rules.isAdmin,
createOneProduct: Rules.isAdmin,
updateOneProduct: Rules.isAdmin,
// deleteOneProduct : Rules.isAdmin,
S3ImageUpload: Rules.isAdmin,
signup : Rules.signup,
},
})