Skip to content
Init is coming / May 19 - 23
Back

[CLOSED] How to create a role based application?

  • 1
  • Accounts
  • Web
Susmita
16 May, 2023, 14:42

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.

TL;DR
The user wants to create a role-based application where there are two roles: user and admin. The admin should be able to directly add blogs to the website, while users have to send a request to the admin via a contact form. They are seeking help and directions for this in a React app. Solution: - Create two collections: `posts` and `posts_submissions` for users. - Create an admin team (`admin`) and add the admin user to this team. - set permissions for the `posts` collection to allow any read and write access by the `team:admin`. - Enable document security for the `posts_sub
Binyamin
16 May, 2023, 15:02

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

joeyouss
16 May, 2023, 16:41

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.

Susmita
18 May, 2023, 06:45

logic is good but I might get stuck.

Susmita
18 May, 2023, 06:46

Let me first try with all users thing

Susmita
18 May, 2023, 06:46

After that I'll think about the admin role

dlohani
18 May, 2023, 07:16

How I would do it

  1. Create two collections (posts, posts_submissions for users)
  2. create admin team (admin) and add admin user to this team
  3. posts permission -> any read, write: team:admin
  4. posts_submissions -> document security turned on, give create permission to any logged in users, and write permission to team:admin for document give read and write permission user:userId (creator)
  5. When user log in, check if they are admin via team membership
  6. If admin -> submit post should save to posts collection
  7. if not admin -> submit post should save to posts_submissions collection 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
  8. you can make a admin panel where admins can see lists of posts in posts_submission and when they click publish/accept -> create on posts and delete from posts_submissions
Susmita
18 May, 2023, 07:19

Great! I'll try this out

dlohani
18 May, 2023, 07:20

Do you like this solution ?

Susmita
18 May, 2023, 07:20

Yes

dlohani
18 May, 2023, 08:24

Let me know how it goes when you do.

safwan
18 May, 2023, 09:24

pretty much the same thing I do for my mobile app. +1

Susmita
18 May, 2023, 10:13

Sure!

joeyouss
1 Jun, 2023, 19:56

Hi @Susmita shall we close this if its resolved?

Susmita
2 Jun, 2023, 05:34

Close this. I'll open later on if needed. Currently not working with roles.

safwan
2 Jun, 2023, 07:21

[CLOSED] How to create a role based application?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more