Yes, but the PR you’ve looked at was closed since I didn’t like the approach. What I would recommend is to set up an umbrella app with two separate web apps that each has their own Pow setup.
It’s possible to run Pow with two different user schemas in the same web app too, but all the work lies on the shoulders of the developer.
If you go down that route (I strongly recommend just separating the context with an umbrella app, or instead have user roles), then you would need to set up both routes and endpoint to handle multiple contexts, as well as some handling of routes.
Something like this (untested):
# endpoint.ex
plug Plug.Session,
otp_app: :my_app,
user: MyApp.Admins.Admin,
current_user_assigns_key: :current_admin,
session_key: "admin_auth",
session_store: {Pow.Store.CredentialsCache, ttl: :timer.minutes(30), namespace: "admin_credentials"},
routes_backend: MyAppWeb.AdminPowRoutes
plug Plug.Session, otp_app: :my_app
# router.ex
pipeline :admin do
plug Pow.Plug.Session,
user: MyApp.Admins.Admin,
current_user_assigns_key: :current_admin,
session_key: "admin_auth",
session_store: {Pow.Store.CredentialsCache, ttl: :timer.minutes(30), namespace: "admin_credentials"},
routes_backend: MyAppWeb.AdminPowRoutes
end
scope "/admin", as: "admin" do
pipe_through [:browser, :admin]
pow_routes()
end
scope "/" do
pipe_through :browser
pow_routes()
end
# admin_pow_routes.ex
defmodule MyAppWeb.AdminPowRoutes do
use Pow.Phoenix.Routes
alias MyAppWeb.Router.Helpers, as: Routes
def url_for(conn, verb, vars \\ [], query_params \\ []) do
plug = admin_namespace(plug)
Pow.Phoenix.Routes.url_for(conn, plug, verb, vars, query_params)
end
def path_for(conn, plug, verb, vars \\ [], query_params \\ []) do
plug = admin_namespace(plug)
Pow.Phoenix.Routes.path_for(conn, plug, verb, vars, query_params)
end
defp admin_namespace(plug) do
[web_module | rest] = Module.split(plug)
Module.concat([web_module, "Admin"] ++ rest)
end
end
You can take a look at the thought process I went through when I was working on this in the #24 #53 and #56 issues.