User context
How do I add contexts for different types of users? For example user type a (normal user), user type b and user type c (both with a dashboard like admin)?
10 Replies
Hi @Bruno Njeru. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To add contexts for different types of users in Wasp, including normal users and those with dashboard access like admins, you can implement a role-based access control (RBAC) system. While Wasp doesn't have built-in RBAC support yet, you can create a custom solution. Here's how you can approach this:
1. Add a role field to your User entity:
2. In your queries and actions, check the user's role to determine access:
3. For pages that require specific roles, use the
authRequired
property and check the user's role in the component:
This approach allows you to create different contexts for various user types. You can extend this concept to include more granular permissions as needed.
For more information on accessing the logged-in user and implementing authorization, you can refer to:
- Accessing the logged-in user (https://wasp-lang.dev/docs/auth/overview#accessing-the-logged-in-user)
- Updating Operations to Check Authentication (https://wasp-lang.dev/docs/tutorial/auth#updating-operations-to-check-authentication)
Note that Wasp is planning to add built-in support for role-based access control in future versions, which will make this process more straightforward Github Issue: Support for Permissions (Access Control) (https://github.com/wasp-lang/wasp/issues/584).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Bruno Njeru, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Ok thanks will try that. How about adding a form for the two conexts user type b and user type c after they sign up. They are user type a by default but may wish to change their role. Something like https://settleasy.com/ which was made by wasp
@kapa.ai
Let me check the knowledge base for you again. One moment! :books:
Sorry @Bruno Njeru, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
@kapa.ai
Let me check the knowledge base for you again. One moment! :books:
Sorry @Bruno Njeru, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
Ok
@kapa.ai
Let me check the knowledge base for you again. One moment! :books:
Sorry @Bruno Njeru, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
Lol, looks like the bot broke 😄
There isn't a first-class construct for an extra form on signup, but you can easily implement extra forms for different types of users on a page Wasp will link to after user successfully signs up.
For the redirect, you can use this: https://wasp-lang.dev/docs/auth/overview#onauthsucceededredirectto-string
@Bruno Njeru Also take a look at:
- https://github.com/wasp-lang/wasp/issues/2277
Ok thanks
Wohooo @Bruno Njeru, you just became a Waspeteer level 1!