caslu
How to create User Organization after registration in Ash Multi-tenancy?
Hello everyone, I’m building a collaborative editor where users can belong to multiple teams. I’ve decided to set up multi-tenancy on my user resource using the context strategy. So far, so good. However, Ash’s default behavior seems to require a team to be created before a user can be created and associated with it. This makes sense in general, but I need a different approach.
If you look at Notion, Figma, Vercel, Supabase, and many other applications with a “team” (organization, group, etc.) architecture, you’ll notice that they often register the user first. Then, the application creates a default organization, often using the user’s username, name, or other information.
Is there a way to adapt Ash’s expected flow to achieve this pattern? Something like:
User registration → Onboarding → Create user organization → Redirect to app home
I realize this is likely more of a design consideration than an Ash issue. If anyone has already tackled and solved this, I’d greatly appreciate any help. Thanks again, everyone! ![]()
Marked As Solved
zachdaniel
Ah, sorry was a bit distracted and didn’t realize this was the same thread.
You can create an organization right there in that handler if one doesn’t exist yet for that user, and then you can set the tenant on the action. If you want to do it transactionally in the case that something goes wrong.
action :send_magic_link_request do
transaction? true
argument :user_params, :map, allow_nil?: false
run fn input, _ ->
# get org for users email
# if it doesn't exist, make it
org = get_or_create_org(...)
strategy = Info.strategy!(User, :magic_link)
Strategy.action(strategy, :request, input.arguments.user_params, tenant: org)
end
end
Then you can call that generic action from your controller.
Also Liked
zachdaniel
My suggestion would be to create the users organization immediately on register, and then allow them to update/customize it after the fact. You can attach before/after action hooks to the register action for example.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









