
How to authenticate users based on their roles? suppose I have customer, manager and admin. I want only admin to login to my website! How can I achieve that?

Middleware
In the future where Appwrite will add middleware it will be straightforward.
As of now you can choose one of the following workarounds:
Delete session upon login
Create a function, let it trigger on users.*.sessions.*.create
, then
- Check if the user has the applicable role,
- If not use Users
deleteSessions
and kick that user out. https://appwrite.io/docs/server/users?sdk=nodejs-default#usersDeleteSessions
Limit access
This will require a bit more effort, but in the long-term is easy to maintain and makes more sense.
Limit all protected resources
- functions
- collections
- storage Only to a given role.
You can also just limit the edit
one for example in your collections

hmm where do i create a role ? in User Preferences or should I create a teams and check there?

In teams Like here for example: https://appwrite.io/docs/client/teams?sdk=web-default#teamsUpdateMembershipRoles

ok let me check and see how I can implement it there!

I got stucked in something. I want to create a sign up for user and add this user to a team but it shows error on this
AppwriteException: general_unauthorized_scope, User (role: guests) missing scope (teams.write) (401)

If someone want to write to a team, it most be
- Team owner - the one who created the team.
- Server side SDK

Can I create a membership in teams without authentication or team owners from server side functions?

Yes, This when Teams are much easier to use When you're using them in server side no email is being send and all the logic happened on the spot.

oh okay let me try that

I have tried deploying the function

but getting error like this :
Docker Error: mv: cannot stat '/usr/code/main.dart': No such file or directory

Did you deploy using the Appwrite CLI like the docs suggest?

yes i was using parameter --code="." instead of --code="functions/New Functions" but it wasn't mentioned in the docs as I checked.. I figured it out by looking at the attached picture or is it mentioned anywhere in docs?

The suggested approach is mentioned in this paragraph: https://appwrite.io/docs/functions#gettingStarted

ok

and How do i use queries in teams ?

i want to get all the team list with query = email

you would need to use the list team memberships API: https://appwrite.io/docs/client/teams?sdk=web-default#teamsListMemberships. Try to query just like you would against list documents

Yes i tried but it didn't work

query: { "userEmail", "abc@email.com" }

Please create a new <#1072905050399191082> post after reading the docs on queries
Recommended threads
- error code:524 for functions running lon...
We are having this issue, no longer the function runtime or code, if it goes longer than 1 minute, there's no logs at all, just this error: **error code: 524**
- Invalid `specification` param: Specifica...
I'm self-hosting my appwrite instance on my Macbook, and I created a Python function using the command `appwrite init functions` and it outputed the below into ...
- Local function throws EACCES error when ...
I am developing an Appwrite function locally. Up until now, the process has been as smooth as butter: I edit my files, save them, and this triggers a rebuild of...
