W
Wasp-lang6mo ago
Soham

How to implement Company Based Custom Auth For OpenSaaS ?

I want to make enterprise SAAS. First user registers a company on the first sign up who is super admin. Then Super Admin can Register other users providing then other roles like systemadmin,user,customer etc.
3 Replies
kapa.ai
kapa.ai6mo ago
Hi @Soham. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To implement a company-based custom authorization system in OpenSaaS using Wasp, you can follow these steps: 1. Add a role field to the User entity: This will allow you to assign different roles to different users, such as superadmin, systemadmin, user, customer, etc. 2. Check the role in your queries/actions: When a user tries to execute a query or action, you can check their role to determine if they should be allowed to do so. If they are not allowed, you can throw an HTTP 403 error. 3. Create a Company entity: This entity can represent the companies that users can register. The first user who registers a company can be assigned the superadmin role. 4. Allow the superadmin to register other users: The superadmin can then register other users and assign them roles within the company. Here is an example of how you might define the User and Company entities:
model User {
id Int @id @default(autoincrement())
email String @unique
role String
Company Company @relation(fields: [companyId], references: [id])
companyId Int
}

model Company {
id Int @id @default(autoincrement())
name String @unique
users User[]
}
model User {
id Int @id @default(autoincrement())
email String @unique
role String
Company Company @relation(fields: [companyId], references: [id])
companyId Int
}

model Company {
id Int @id @default(autoincrement())
name String @unique
users User[]
}
In this example, each User is associated with a Company, and each Company has multiple users. The role of each User can be checked in your queries and actions to determine what they are allowed to do. Please note that this is a basic example and you might need to adjust it to fit your specific needs. Also, Wasp currently doesn't provide a default support for role-based access control (RBAC), but they have plans to add it in the future. For more information, you can check the OpenSaaS template (https://opensaas.sh/) provided by Wasp, which comes with the concept of admins and even has an admin dashboard in it. Sources: - Discord support thread: Hi, how do you add authorization ? > Answers (https://discord.com/channels/686873244791210014/1211733266235916358) - Discord support thread: Prisma schema for a github-like multi-tenant saas > Original post (https://discord.com/channels/686873244791210014/1215047437929160724) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Soham, 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?
Soham
Soham6mo ago
Seems like a good answer. What are some free email providers to use with open saas ? @kapa.ai
martinsos
martinsos6mo ago
Sounds like a good answer indeed! Check out https://wasp-lang.dev/docs/advanced/email @Soham for list of some providers we recommend, they have free tiers.
Want results from more Discord servers?
Add your server