BryanJBryce

BryanJBryce

Ash Authentication – Generated UI and multiple auth Resources

I realize this is pushing the boundaries of tested space for this library, but I’ve got two Auth resources (Admin and User, one is global the other schema-based both with their own token tables) and I’m trying to figure out how to use the generate UI with them, but have them be separated. The default when you do that is this fun UI:

I tried this:

 scope "/admin", AppWeb do
    pipe_through :browser

    auth_routes AdminAuthController, App.Accounts.Admin,
      path: "/admin/auth",
      sign_in_path: "/admin/sign-in",
      register_path: nil,
      reset_path: "/admin/reset"
  end
  scope "/", AppWeb do
    pipe_through :browser

    # User authentication routes
    auth_routes AuthController, App.Accounts.User,
      path: "/auth",
      sign_in_path: "/sign-in",
      register_path: "/register",
      reset_path: "/reset"

No dice:

== Compilation error in file lib/app_web/router.ex ==
** (ArgumentError) AshAuthentication.Phoenix.StrategyRouter has already been forwarded to. A module can only be forwarded a single time
(phoenix 1.7.18) lib/phoenix/router/scope.ex:87: Phoenix.Router.Scope.register_forwards/3
(phoenix 1.7.18) lib/phoenix/router/scope.ex:58: Phoenix.Router.Scope.route/8
lib/app_web/router.ex:74: (module)

Most Liked

zachdaniel

zachdaniel

Creator of Ash

I’ve pushed something up to main that you can try.

First define a plug that wraps AshAuthentication.Phoenix.StrategyRouter like so:

defmodule MyPlugThatShouldNotBeNecessary do
  defdelegate init(opts), to: AshAuthentication.Phoenix.StrategyRouter
  defdelegate call(conn, opts), to: AshAuthentication.Phoenix.StrategyRouter
end

then in your second call to auth_routes add strategy_router_plug: MyPlugThatShouldNotBeNecessary

This seems like a very strange limitation, but this should get you around it. If you wouldn’t mind, a PR with docs for this or an issue reminding us to add some docs around it would be great.

zachdaniel

zachdaniel

Creator of Ash

:thinking: A module can only be forwarded to a single time??? This is news to me :cry:

Looking into it there are certain kinds of workarounds that could be done:

https://github.com/graphql-elixir/plug_graphql/issues/7

but honestly nothing I can think of that is something that you could apply yourself in this situation. I would first really like to understand why you can’t forward to the same plug multiple times from different routes??

BryanJBryce

BryanJBryce

I’ll get that done :saluting_face:

Where Next?

Popular in Questions Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
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
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
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
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement