New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can Shield help ensure ownership? #57
Comments
Hey @everdev 👋, I see what you are trying to do. Customer, in case of the example, doesn't ensure that the basket belongs to the particular user. I would say that these two problems are of a bit different nature. Let me explain the idea; When using Prisma only as a Your case is, in my opinion, a bit different. In a way, it is more flexible which might in terms of security not be the best outcome. Nevertheless, let's se what we can do. Since you are passing the A quick code example might be something like this; const isOwnerOfTheBasket = rule()(async (parent, args, ctx, info) => {
const basketID = args.data.basketID
const userID = ctx.user.id
return ctx.db.exists.Basket({
id: basketID,
owner: { id: userID }
})
}) If you are not yet familiar with Graphcool like permissions approach, I encourage you to read the old permissions docs and learn as much as possible from the idea. To give you a bit of headstart, permission queries have been renamed to https://www.graph.cool/docs/reference/auth/authorization/overview-iegoo0heez To answer your last two questions, yes! Both Hope this answers your question! 🙂 Also, if you have some time, please open up another issue with feature/docs request for example with |
Perfect! I think that example code will work well :) |
Thanks for maintaining a great project :)
I'm hoping to use
graphql-shield
to lock down my API. Currently I'm using https://github.com/maticzav/graphql-middleware-forward-binding to forward requests to the auto-generated resolvers.Based on your post (https://medium.com/@maticzav/graphql-shield-9d1e02520e35), does the
isCustomer
function ensure that customers can only add items to their own basket? Or how would you add that logic to the function?When calling
addItemToBasket
, are theargs
of that mutation passed along toisCustomer
?I'm using a JWT in the auth header, with a unique ID in the payload. Does that come through in the
ctx
variable in some way?Thanks!
The text was updated successfully, but these errors were encountered: