Skip to content
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

Reserved parameters content resource filters #7940

Open
lukejacksonn opened this issue Dec 3, 2024 · 0 comments
Open

Reserved parameters content resource filters #7940

lukejacksonn opened this issue Dec 3, 2024 · 0 comments

Comments

@lukejacksonn
Copy link

lukejacksonn commented Dec 3, 2024

Goal

I've been looking at different use cases for Sanity and one that I thought of recently was a kind of "multi-tenant" setup whereby many vendors could log into a single Sanity project and manage their own products in a dataset via a shared studio.

This sounds appealing to me as a developer looking to create small online "marketplaces" for specific niches as:

  • You would only have to manage one project, dataset and deployment
  • You don't need to build a custom back office for vendors to manage their products
  • Sanity already handles project user invitations and authentication
  • Sanity allows you to create roles and permissions for individual users

Problem

I started to explore the idea and got as far as looking at how I would go about restricting vendors read/write ability to a subset of documents in the dataset. Generally how I would go about this for a small handful of users is to:

  1. Create a custom role for each vendor with a content resource filter like vendor == "[email protected]"
  2. Filter out documents of a given type in the studio by getting the logged in user and applying the above filter
  3. Use initial template values to ensure vendors can create and publish documents that respects the above filter

Which I think would work in theory (haven't actually tried hooking it all up) but it doesn't scale particularly well as it would require a custom role and content resource filter be created for each vendor.

Proposed Solution

One way that this could be made more scalable would be to allow for reserved parameters to be used within content resource filters. Assuming that the API has access to the current studio user's access token, it could extract a unique identifier for the user and pass that as a parameter to the content resource filter, this would allow for a content resource configuration like:

image

Given my understanding of how roles, permissions and content resources filters work currently, I don't think this would be a significant technological lift from what already exists today (of course, I could be way off the mark here!) but it would unlock some more interesting use cases for Sanity and the Studio.

Alternatives

Given that the proposed solution does not exist currently, the only real way I can see of achieve this multi-tenant setup at scale is to "eject" from the studio and build my own UI and API layers to allow authenticated vendors to create and manage products on the platform (essentially forgoing all the benefits and capabilities of the studio).


Thanks for reading and please do let me know if there is something I have missed that exists already to solve this problem 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant