giusdp

giusdp

Ash multi-tenant umbrella app project

I was wondering if it’d make sense and how feasible it is to have a multi-tenant project composed of 2 phoenix apps.

One app is just an API with ash_json_api to serve the end-users, and the other is a dashboard on top of the same database, for the tenants.
The dashboard app with a AshAuthentication set up for the main users (magic link login) and the API app another AshAuthentication setup with email/password.

Both apps use the same database with schema-based multitenancy, but the dashboard also operates on the public schema for the main users (for user creation and login).

This way I could cleanly separate the 2 sides of the system, but then it’d be a mess having to keep in sync the shared domain and resources. In one I’d have to put json api routes and in the other no.

I bet there is something I’m missing and I could be able to derive the 2 apps from the same resources. Right now it’s one single otp_app that offers both json api routes and html dashboard routes. One problem is that Ash authentication is picking up both the main-user and end-user resources when accessing the dashboard (it shows both magic link and email/pass at login, and the conn has both current_user and current_end_user).

I’d like to avoid that. Also what if I need to start scaling and replicate the API? The dashboard side won’t need to scale up, probably , while the api side might receive a lot of traffic. For instance I could have 1 single user that in turn has 1 million end-users. The dashboard is used by 1 and the api is used by 1 million.

So, my question is basically how to organize such project. Would it be possible to separate the project into a multi app monorepo project or an umbrella project where I have:

  • 1 otp_app with all the shared domain and resource (with both dashboard-specific actions and json api routes);
  • 1 app for the dashboard with the router for the dashboard routes + the main accounts domain and resource with ash authentication on top;
  • 1 app for the API which has a very simple router to just redirect to the AshJsonApi Router in the shared app, plus its own end-user domain+resource with another ash authentication.

I didn’t try anything yet and it might be a silly idea that won’t work. I’d like to know from more experienced people how to organize a project like that with ash.

Most Liked

zachdaniel

zachdaniel

Creator of Ash

We often don’t tend to split Ash apps up in that way, but there shouldn’t be any reason you can’t do it :slight_smile:

As for the question about it displaying bot h user resources, IIRC there is an option you can use to restrict which user resources get their authentication strategies displayed. pretty sure its an option in the router code.

zachdaniel

zachdaniel

Creator of Ash

Looks like you’re right, and there is not a way to manually select the resources. I don’t have time to fully test this out myself, but I’ve pushed the changes required to support this to a branch, the PR is here: improvement: allow setting a subset of resources on sign in by zachdaniel · Pull Request #593 · team-alembic/ash_authentication_phoenix · GitHub

You would use this as sign_in_route ...., resources: [A.Specific.Resource]

giusdp

giusdp

Awesome! I think it will be a nice addition. I believe I saw around the forum other people needing something like this, too. I’ll try the branch out as soon as I can

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New

We're in Beta

About us Mission Statement