I want to create a role based application where there will be one user role and another one will be admin role. Admin will be able to add blogs to the website directly while the users have to send request to the admin via a contact form.
I haven't done this kind of thing before. It's gonna be a React app. So, need help and directions.
That's will probably be a more diffcult to demonstrate, but here's are main guidelines.
Teams & Rules Appwrite offers two ways to separate users.
A. Add them to teams https://appwrite.io/docs/client/teams https://appwrite.io/docs/client/teams?sdk=web-default#teamsCreateMembership
B. Add role to a user https://appwrite.io/docs/client/teams?sdk=web-default#teamsUpdateMembershipRoles
You can work your way around it without react, just by using pure js/ts with that logic.
Then, when you get the user object back from Appwrite using this function. (inside a function with a server SDK) https://appwrite.io/docs/server/users?sdk=nodejs-default#usersListMemberships Then you'll be able to filter the results back to frontend
Hi - adding to @Binyamin 's answer
So, for admin:
- Admin runs function "A" (suppose) and this function allows the admin to post the blog directly.
So, for user:
- User runs a function "B" and this function sends a call to a different function "C" which will act as the interface/connecting point between user and admin. Function C is called and it checks with admin for permissions, if the permission is granted, the function returns back to B and tells the user about permission being granted. Next lines in B are, using backend logic you can make the admin run their own logic of A to post the blog.
Does this logic help?
Using roles will be a very good help here.
logic is good but I might get stuck.
Let me first try with all users thing
After that I'll think about the admin role
How I would do it
- Create two collections (
posts,posts_submissionsfor users) - create admin team (
admin) and add admin user to this team postspermission -> any read, write:team:adminposts_submissions-> document security turned on, give create permission to any logged in users, and write permission toteam:adminfor document give read and write permissionuser:userId(creator)- When user log in, check if they are admin via team membership
- If admin -> submit post should save to
postscollection - if not admin -> submit post should save to
posts_submissionscollection For this all you need to change is the collection ID based on if user is admin and server side permissions will validate if user try to mess around - you can make a admin panel where admins can see lists of posts in
posts_submissionand when they click publish/accept -> create onpostsand delete fromposts_submissions
Great! I'll try this out
Do you like this solution ?
Yes
Let me know how it goes when you do.
pretty much the same thing I do for my mobile app. +1
Sure!
Hi @Susmita shall we close this if its resolved?
Close this. I'll open later on if needed. Currently not working with roles.
[CLOSED] How to create a role based application?
Recommended threads
- OAuth login not working on deployed app ...
Hey there, I've been dealing with an issue where I cannot use OAuth on my deployed app - locally everything works fine. I am using react-router in Framework Mo...
- database documents relationships
after migrating from 1.7.4 to 1.8, database get document and list documents is getting results but with no relationship values, the relationship attribute will...
- Getting CORS error when accessing websit...
When accessing my website I'm getting: (index):1 Access to font at 'https://assets.appwrite.io/fonts/inter/Inter-Regular.woff2' from origin 'https://mvp-site-ra...