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
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...