How to authorize based on an id for an entity over multiple resolvers? #194
Unanswered
MrEbbinghaus
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Have you considered using |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am sure this has been discussed at least once on Slack, but here I am again.
Imagine you have the following models:
A Group has Posts and a Post has Comments. (
:group/id
,:post/id
,:comment/id
)You can only see
post
s orcomment
s if you are part of agroup
.Now each of these models has several attributes spread over several resolvers.
How would you implement authorization across multiple resolvers?
The naive solution
Adding a check to each resolver.
This leads to too much redundant code and checks. So not a good solution.
Translate external keys to internal ones
It would be better to make the check if a user can access any resolver with a posts id as input once, with something like this:
(You would allow the key
:authorized-post
only internally and remove it from incoming queries.)This is also good, because it could pass down authorization to children nodes, skipping the authorization for them.
But: This is really tedious to write, and it would be better if this was opaque.
Now to my questions:
Is there a way to implement such... "gates" ... in pathom?
Should I keep all authorized ids in the env?
Can I write a plugin, that does this? When an id appears for the first time and isn't in the env, check if the user is authorized? If not, stop that part of the query. If authorized, continue and add to the env?
Is this a use case for the request cache?
I am quite lost on how to do that nicely.
Beta Was this translation helpful? Give feedback.
All reactions