Ash FrameworkAF
Ash Frameworkโ€ข8mo agoโ€ข
9 replies
ggarciajr

How to model context based multitenancy?

What would be the best approach to load the tenant info into the user when working with context base multitenancy?
- If I use global? true I can log in without knowing the tenant, but I'm not sure what the best strategy to fetch the tenant into after - or during - sign in, given the current_user has no tenant data
- If I use global? false I need the tenant info before sign in, which can be work. I just need to figure it out how to build the magic link with the tenant subdomain - probably a phoenix question though.

Should I define my user resource as?
  multitenancy do
    strategy :context
    attribute :organization_id
  end

  relationships do
    belongs_to :organization, MyApp.Organization
  end


The context multitenancy docs is not clear how this should be mapped.

Also, if I don't add the attribute id and use global? true is there a way to tell ash authentication to load the tenant info it used to log the user in?
Solution
Yes you should likely do that ๐Ÿ™‚
Was this page helpful?