is it possible with SuperTokens to have accounts w...
# support-questions
m
is it possible with SuperTokens to have accounts with multiple users?
r
Hey @mattapperson
Are you talking about our sign in on supertokens.com? We don’t have that yet.
Or are you talking about implementing that feature using supertokens on your app?
m
The latter, in my own app
r
Right. Can you elaborate on the flow a bit more? Maybe give an example use case in detail
m
Sure, basically the idea being that a company can sign up and have N employees have their own logins. I’m thinking I could create sets of roles per account, but the api feels not optimized for this so I’m thinking this could lease to issues.
r
So you essentially want multi tenancy? Where each tenant is an org and each tenant has its own user pool?
m
Not really, no. I just want to support business users who will have multiple users assigned to their account and can see their data to varying degrees based on permissions. Think like slack. 1 user can belong to N accounts, an account can have N users
r
Hmmm. I see.
So this is possible. What you want to do is introduce the concept of something like “accountId”
Wherein multiple users have the same associated account id
The mapping of user id to account id is something you will have to store in your database
Then you want to override the createNewSession function on the backend to add the account id to the user’s session
And then in your api, fetch the accountId from the session and write your api logic based on that
m
Hmmm and then handle the initial account id on login and updating the session to switch between accounts, and updating the permissions the user has based on the active account id
r
So the permissions can still be associated with the user id
m
Can they?
r
This way different users logging into the same account will get their respective permissions
Since their user ids are different
m
But that’s not how that works
Like slack… on one account maybe I have admin permission for that account
While on another I do not
r
Ah so one user id can be a part of multiple account ids as well
m
Right
r
Right. Then you want to store the permissions based userId and account id
m
Indeed
Sorry, I kinda assumed this was a more common flow then maybe it is
r
The way you can do that in supertokens is to associated all roles against a user Id (across all their accountids)
And then override the getroles function to further filter the roles based on the current active account id
And when users switch accounts, update the roles in the session using session.fetchAndSetClaim
m
Got it
Thanks for the help!
r
There may be more edge cases in this flow. Haven’t thought about it fully yet.
But feel free to ask more questions