AE
Ash Elixirβ€’3y ago
minib

AshAuthentication Errors

After I've updated ash packages:
ash 2.5.9 => 2.5.12
ash_authentication 3.7.3 => 3.7.5
ash_authentication_phoenix 1.4.5 => 1.4.6
ash_phoenix 1.2.4 => 1.2.5
ash_postgres 1.3.3 => 1.3.5
ash 2.5.9 => 2.5.12
ash_authentication 3.7.3 => 3.7.5
ash_authentication_phoenix 1.4.5 => 1.4.6
ash_phoenix 1.2.4 => 1.2.5
ash_postgres 1.3.3 => 1.3.5
I got this error:
77 Replies
minib
minibOPβ€’3y ago
[error] #PID<0.706.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.705.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /sign-in
** (exit) an exception was raised:
** (UndefinedFunctionError) function AshAuthentication.Phoenix.Components.Confirmation.__live__/0 is undefined (module AshAuthentication.Phoenix.Components.Confirmation is not available)
AshAuthentication.Phoenix.Components.Confirmation.__live__()
(phoenix_live_view 0.18.11) lib/phoenix_component.ex:1761: Phoenix.Component.live_component/1
(phoenix_live_view 0.18.11) lib/phoenix_live_view/html_engine.ex:35: Phoenix.LiveView.HTMLEngine.component/3
(ash_authentication_phoenix 1.4.6) lib/ash_authentication_phoenix/components/sign_in.ex:119: anonymous fn/2 in AshAuthentication.Phoenix.Components.SignIn.strategy/1
(ash_authentication_phoenix 1.4.6) /Users/egor/projects/open_check/open_status/deps/ash_authentication_phoenix/lib/ash_authentication_phoenix/components/sign_in.ex:103: AshAuthentication.Phoenix.Components.SignIn.render/1
(elixir 1.14.2) lib/enum.ex:1780: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
[error] #PID<0.706.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.705.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /sign-in
** (exit) an exception was raised:
** (UndefinedFunctionError) function AshAuthentication.Phoenix.Components.Confirmation.__live__/0 is undefined (module AshAuthentication.Phoenix.Components.Confirmation is not available)
AshAuthentication.Phoenix.Components.Confirmation.__live__()
(phoenix_live_view 0.18.11) lib/phoenix_component.ex:1761: Phoenix.Component.live_component/1
(phoenix_live_view 0.18.11) lib/phoenix_live_view/html_engine.ex:35: Phoenix.LiveView.HTMLEngine.component/3
(ash_authentication_phoenix 1.4.6) lib/ash_authentication_phoenix/components/sign_in.ex:119: anonymous fn/2 in AshAuthentication.Phoenix.Components.SignIn.strategy/1
(ash_authentication_phoenix 1.4.6) /Users/egor/projects/open_check/open_status/deps/ash_authentication_phoenix/lib/ash_authentication_phoenix/components/sign_in.ex:103: AshAuthentication.Phoenix.Components.SignIn.render/1
(elixir 1.14.2) lib/enum.ex:1780: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
And when I downgraded version back I got another error:
[error] #PID<0.2315.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.2300.0>, stream id 4) terminated
Server: localhost:4000 (http)
Request: GET /sign-in
** (exit) an exception was raised:
** (RuntimeError) found duplicate ID "sign-in-hr" for component AshAuthentication.Phoenix.Components.HorizontalRule when rendering template
(phoenix_live_view 0.18.11) lib/phoenix_live_view/diff.ex:616: anonymous fn/5 in Phoenix.LiveView.Diff.render_pending_components/6
(elixir 1.14.2) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(stdlib 4.1.1) maps.erl:411: :maps.fold_1/3
(phoenix_live_view 0.18.11) lib/phoenix_live_view/diff.ex:609: Phoenix.LiveView.Diff.render_pending_components/6
(phoenix_live_view 0.18.11) lib/phoenix_live_view/diff.ex:145: Phoenix.LiveView.Diff.render/3
(phoenix_live_view 0.18.11) lib/phoenix_live_view/static.ex:252: Phoenix.LiveView.Static.to_rendered_content_tag/4
(phoenix_live_view 0.18.11) lib/phoenix_live_view/static.ex:135: Phoenix.LiveView.Static.render/3
(phoenix_live_view 0.18.11) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
(phoenix 1.7.0-rc.2) lib/phoenix/router.ex:425: Phoenix.Router.__call__/5
(open_status 0.1.0) lib/open_status_web/endpoint.ex:1: OpenStatusWeb.Endpoint.plug_builder_call/2
(open_status 0.1.0) lib/plug/debugger.ex:136: OpenStatusWeb.Endpoint."call (overridable 3)"/2
(open_status 0.1.0) lib/open_status_web/endpoint.ex:1: OpenStatusWeb.Endpoint.call/2
(phoenix 1.7.0-rc.2) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
[error] #PID<0.2315.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.2300.0>, stream id 4) terminated
Server: localhost:4000 (http)
Request: GET /sign-in
** (exit) an exception was raised:
** (RuntimeError) found duplicate ID "sign-in-hr" for component AshAuthentication.Phoenix.Components.HorizontalRule when rendering template
(phoenix_live_view 0.18.11) lib/phoenix_live_view/diff.ex:616: anonymous fn/5 in Phoenix.LiveView.Diff.render_pending_components/6
(elixir 1.14.2) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(stdlib 4.1.1) maps.erl:411: :maps.fold_1/3
(phoenix_live_view 0.18.11) lib/phoenix_live_view/diff.ex:609: Phoenix.LiveView.Diff.render_pending_components/6
(phoenix_live_view 0.18.11) lib/phoenix_live_view/diff.ex:145: Phoenix.LiveView.Diff.render/3
(phoenix_live_view 0.18.11) lib/phoenix_live_view/static.ex:252: Phoenix.LiveView.Static.to_rendered_content_tag/4
(phoenix_live_view 0.18.11) lib/phoenix_live_view/static.ex:135: Phoenix.LiveView.Static.render/3
(phoenix_live_view 0.18.11) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
(phoenix 1.7.0-rc.2) lib/phoenix/router.ex:425: Phoenix.Router.__call__/5
(open_status 0.1.0) lib/open_status_web/endpoint.ex:1: OpenStatusWeb.Endpoint.plug_builder_call/2
(open_status 0.1.0) lib/plug/debugger.ex:136: OpenStatusWeb.Endpoint."call (overridable 3)"/2
(open_status 0.1.0) lib/open_status_web/endpoint.ex:1: OpenStatusWeb.Endpoint.call/2
(phoenix 1.7.0-rc.2) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
Any ideas what went wrong? Will appreciate any suggestions. I don't have any overrides if it matters
ZachDaniel
ZachDanielβ€’3y ago
πŸ€” I think @jart will need to chime in Actually have you tried force recompiling after updating?
minib
minibOPβ€’3y ago
yes, I have tried that
ZachDaniel
ZachDanielβ€’3y ago
Kk. I’ll update ash_hq to the latest for those libraries and see if I get the same thing Yeah, I'm getting these errors too πŸ€” I think I see where it is lemme confirm So for some reason:
AshAuthentication.Info.authentication_strategies(AshHq.Accounts.User)
AshAuthentication.Info.authentication_strategies(AshHq.Accounts.User)
is returning the addons as well and that is causing this issue
minib
minibOPβ€’3y ago
hmm
ZachDaniel
ZachDanielβ€’3y ago
Its definitely an underlying thing, will fix found it I just pushed to main, can you try that out? Of ash_authentication
minib
minibOPβ€’3y ago
sure I still get
found duplicate ID "sign-in-hr" for component AshAuthentication.Phoenix.Components.HorizontalRule when rendering template
found duplicate ID "sign-in-hr" for component AshAuthentication.Phoenix.Components.HorizontalRule when rendering template
btw I also had to override ash_authentication, because of
Dependencies have diverged:
* ash_authentication (https://github.com/team-alembic/ash_authentication.git)
the dependency ash_authentication in mix.exs is overriding a child dependency:

> In mix.exs:
{:ash_authentication, [env: :prod, git: "https://github.com/team-alembic/ash_authentication.git"]}

> In deps/ash_authentication_phoenix/mix.exs:
{:ash_authentication, "~> 3.5", [env: :prod, hex: "ash_authentication", repo: "hexpm", optional: false]}

Ensure they match or specify one of the above in your deps and set "override: true"
** (Mix) Can't continue due to errors on dependencies
Dependencies have diverged:
* ash_authentication (https://github.com/team-alembic/ash_authentication.git)
the dependency ash_authentication in mix.exs is overriding a child dependency:

> In mix.exs:
{:ash_authentication, [env: :prod, git: "https://github.com/team-alembic/ash_authentication.git"]}

> In deps/ash_authentication_phoenix/mix.exs:
{:ash_authentication, "~> 3.5", [env: :prod, hex: "ash_authentication", repo: "hexpm", optional: false]}

Ensure they match or specify one of the above in your deps and set "override: true"
** (Mix) Can't continue due to errors on dependencies
ZachDaniel
ZachDanielβ€’3y ago
Yeah, okay I think I see how that could be happening too πŸ€” do you have multiple resources that can be used to sign in?
minib
minibOPβ€’3y ago
like different kind of users?
ZachDaniel
ZachDanielβ€’3y ago
yeah
minib
minibOPβ€’3y ago
then just one But I have both password and github everything was fine a week ago
ZachDaniel
ZachDanielβ€’3y ago
Yeah, we made changes to the underlying library to support custom strategies Which is a great thing πŸ™‚ But there are a few kinks it seems
minib
minibOPβ€’3y ago
okay
ZachDaniel
ZachDanielβ€’3y ago
I suspect that the duplicate ids error was there in previous versions thats just a warning in the browser console right?
minib
minibOPβ€’3y ago
nope, that a proper error
ZachDaniel
ZachDanielβ€’3y ago
oh, really?
minib
minibOPβ€’3y ago
No description
minib
minibOPβ€’3y ago
No description
ZachDaniel
ZachDanielβ€’3y ago
gotcha Okay...does your user resource appear in multiple apis? The reason I ask is that the hr is defined once per resource it thinks you could authenticate as What does this return for you in iex
AshAuthentication.authenticated_resources(:your_otp_app)
AshAuthentication.authenticated_resources(:your_otp_app)
jart
jartβ€’3y ago
Thanks for jumping in Zach. Sorry about leaving a mess. I’ll take a look at your fixes today and try and write tests to avoid regressions.
ZachDaniel
ZachDanielβ€’3y ago
There is still one more that I don't understand, which is the duplicate horizontal rule I accidentally pushed the first fix straight to main though πŸ˜†
jart
jartβ€’3y ago
Nothing like a YOLO release to wake you up in the morning.
ZachDaniel
ZachDanielβ€’3y ago
This is why I do explicit releases in Ash
jart
jartβ€’3y ago
Hey it won’t release if it doesn’t build.
ZachDaniel
ZachDanielβ€’3y ago
true true
minib
minibOPβ€’3y ago
it does I guess, I had to add it to another API's registry, where it was related to. Like MyApp.Accounts.User I've added to MyApp.Blog.Registry because of author relation in MyApp.Blog.Post otherwise it was compile time erroring Resources MyApp.Accounts.User must be included in the registry.
ZachDaniel
ZachDanielβ€’3y ago
Ah, okay So we can fix that
minib
minibOPβ€’3y ago
πŸ™
ZachDaniel
ZachDanielβ€’3y ago
but also you don't actually have to add it to your other registry if you don't want to I need to update the error message
minib
minibOPβ€’3y ago
oo i felt it wasn't right
ZachDaniel
ZachDanielβ€’3y ago
But you can do
belongs_to :author, MyApp.Accounts.User do
api MyApp.Accounts
end
belongs_to :author, MyApp.Accounts.User do
api MyApp.Accounts
end
You just need to configure which api to use if its not in the same one as the resource
minib
minibOPβ€’3y ago
relationships do
belongs_to :created_by, OpenStatus.Accounts.User do
api OpenStatus.Accounts
allow_nil? false
end

has_many :events, OpenStatus.Monitors.Event
end
relationships do
belongs_to :created_by, OpenStatus.Accounts.User do
api OpenStatus.Accounts
allow_nil? false
end

has_many :events, OpenStatus.Monitors.Event
end
but i have this already
frankdugan3
frankdugan3β€’3y ago
Yeah, that tripped me up the other day! I just started using split APIs now that it's a lot easier to cross the boundaries w/ resources.
ZachDaniel
ZachDanielβ€’3y ago
πŸ€” that should be all you need to do Perhaps double check the error message after you do that? i.e remove user from the blog context
minib
minibOPβ€’3y ago
you mean registry? i just removed it from the registy
ZachDaniel
ZachDanielβ€’3y ago
yeah, sorry, registry πŸ˜†
frankdugan3
frankdugan3β€’3y ago
I haven't split up my large app yet, but I'm interested in seeing how much that improves compile times once I do.
minib
minibOPβ€’3y ago
then I get Resources OpenStatus.Accounts.User must be included in the registry
ZachDaniel
ZachDanielβ€’3y ago
πŸ€” πŸ€” πŸ€” Do you have any other resources that point to that?
minib
minibOPβ€’3y ago
anyways everything was fine until I've updated dependencies to the latest, today
ZachDaniel
ZachDanielβ€’3y ago
πŸ€” I'm on all the latest and I don't have that issue w/ crossing apis... I'll push something up that provides a better error message and maybe that will help
minib
minibOPβ€’3y ago
i have two resources under OpenStatus.Monitors with relations to OpenStatus.Accounts.User and so far there are only two API in my project, Accounts and Monitors i thought it's strange, but thought it's for the sake of compiler optimization or something, was going to ask you later i can share the repo with you if it would help
ZachDaniel
ZachDanielβ€’3y ago
I'll push up an improvement to the error message in just a sec and it should tell us exactly what it thinks the issue is πŸ™‚
minib
minibOPβ€’3y ago
cool, standing by
frankdugan3
frankdugan3β€’3y ago
Meanwhile, are both the apis added to config.exs? That's easy to forget to do!
minib
minibOPβ€’3y ago
yup
config :open_status,
ash_apis: [OpenStatus.Accounts, OpenStatus.Monitors]
config :open_status,
ash_apis: [OpenStatus.Accounts, OpenStatus.Monitors]
like I said it was working last week
ZachDaniel
ZachDanielβ€’3y ago
That is very strange.
minib
minibOPβ€’3y ago
agree
ZachDaniel
ZachDanielβ€’3y ago
You didn't make any changes to your resources?
minib
minibOPβ€’3y ago
no, I've set up the auth, logged-in and was working on liveviews, until today I've decided to update the deps
ZachDaniel
ZachDanielβ€’3y ago
oh, well That could be something to do with only doing a partial recompile while you're working
minib
minibOPβ€’3y ago
i've changed the resources, last time last week, but it was ok until the deps update
ZachDaniel
ZachDanielβ€’3y ago
and so the registry didn't recompile or something along those lines but when you pull latest ash, all the ash stuff has to recompile which is bad, it should have told you about this right away but I think that is the reason you didn't see it before.
minib
minibOPβ€’3y ago
today I've also tried to remove _build dir and recompile the whole thing
ZachDaniel
ZachDanielβ€’3y ago
Yeah, so the idea here is that it was broken before, but the error wasn't showing because of partial recompilation so clearing _build wouldn't help
minib
minibOPβ€’3y ago
nope
ZachDaniel
ZachDanielβ€’3y ago
okay can you try main? I made the validation much simpler and had it produce a much better error message
minib
minibOPβ€’3y ago
main ash_auth? it's in my mix.exs already, or you mean another package?
# mix.exs
{:ash, "~> 2.5"},
{:ash_postgres, "~> 1.3"},
# {:ash_authentication, "~> 3.7"},
{:ash_authentication, github: "team-alembic/ash_authentication", override: true},
{:ash_authentication_phoenix, "~> 1.4"},
# mix.exs
{:ash, "~> 2.5"},
{:ash_postgres, "~> 1.3"},
# {:ash_authentication, "~> 3.7"},
{:ash_authentication, github: "team-alembic/ash_authentication", override: true},
{:ash_authentication_phoenix, "~> 1.4"},
ZachDaniel
ZachDanielβ€’3y ago
Main ash
minib
minibOPβ€’3y ago
okay
ZachDaniel
ZachDanielβ€’3y ago
And you'd need to do mix deps.update ash_authentication to pull latest main of ash_authentication anyway (a common thing that trips people up, so just letting you know)
minib
minibOPβ€’3y ago
I'll remove _build and deps
ZachDaniel
ZachDanielβ€’3y ago
Shouldn't be necessary, but its fine if you do
minib
minibOPβ€’3y ago
got this
Dependencies have diverged:
* ash (https://github.com/ash-project/ash.git)
the dependency ash in mix.exs is overriding a child dependency:

> In mix.exs:
{:ash, [env: :prod, git: "https://github.com/ash-project/ash.git"]}

> In deps/ash_authentication/mix.exs:
{:ash, "~> 2.5 and >= 2.5.11", [env: :prod, hex: "ash", repo: "hexpm"]}

Ensure they match or specify one of the above in your deps and set "override: true"
** (Mix) Can't continue due to errors on dependencies
Dependencies have diverged:
* ash (https://github.com/ash-project/ash.git)
the dependency ash in mix.exs is overriding a child dependency:

> In mix.exs:
{:ash, [env: :prod, git: "https://github.com/ash-project/ash.git"]}

> In deps/ash_authentication/mix.exs:
{:ash, "~> 2.5 and >= 2.5.11", [env: :prod, hex: "ash", repo: "hexpm"]}

Ensure they match or specify one of the above in your deps and set "override: true"
** (Mix) Can't continue due to errors on dependencies
going to override
ZachDaniel
ZachDanielβ€’3y ago
Ah, yeah you'll always have to do that if you set ash or any library that has something depending on it to a github dependency
minib
minibOPβ€’3y ago
ooo i guess the new error message works! πŸ™‚
ZachDaniel
ZachDanielβ€’3y ago
πŸ₯³
minib
minibOPβ€’3y ago
so yeah I had another resouse in the api with a relation to User which didn't specify Accounts api
ZachDaniel
ZachDanielβ€’3y ago
Got it, was hoping that was the issue πŸ˜†
minib
minibOPβ€’3y ago
the sign-in also works now! huge thanks to all of you guys!
ZachDaniel
ZachDanielβ€’3y ago
I've made PRs to ash_authentication & ash_authentication_phoenix to solve it in the future so that if someone actually does have their user in multiple apis on purpose, they won't encounter the issue that you did Glad to help! Thank you for helping us work out the kinks and being patient πŸ™‚ Even more cool stuff is coming for ash_authentication over time which is really exciting.
minib
minibOPβ€’3y ago
can't wait πŸ™‚ marking the tread as resolved
ZachDaniel
ZachDanielβ€’3y ago
I beat you to it πŸ˜†
frankdugan3
frankdugan3β€’3y ago
warning: Routes.module_offering_index_url/2 is undefined (module Routes is not available or is yet to be defined)
lib/decentralize/learning/notifiers/learning_notifier.ex:22: Decentralize.Student.LearningNotifier.notify/1

** (EXIT from #PID<0.111.0>) an exception was raised:
** (RuntimeError) Could not determine api for Decentralize.Learning.ModuleOffering.facilitator. Please do one of the following:

1. Add the resource to the registry `Elixir.Decentralize.Learning.Registry`

2. Set the `api` option on the relationship, for example:


belongs_to :facilitator, Decentralize.Authentication.User do
api SomeOtherApi
end
warning: Routes.module_offering_index_url/2 is undefined (module Routes is not available or is yet to be defined)
lib/decentralize/learning/notifiers/learning_notifier.ex:22: Decentralize.Student.LearningNotifier.notify/1

** (EXIT from #PID<0.111.0>) an exception was raised:
** (RuntimeError) Could not determine api for Decentralize.Learning.ModuleOffering.facilitator. Please do one of the following:

1. Add the resource to the registry `Elixir.Decentralize.Learning.Registry`

2. Set the `api` option on the relationship, for example:


belongs_to :facilitator, Decentralize.Authentication.User do
api SomeOtherApi
end
^ EXCELLENT error message, so much better! :ashley:
ZachDaniel
ZachDanielβ€’3y ago
Some of these things are like no brainers once you realize it, but its hard to see when I'm so familiar with the issue but thats something that people encounter all the time, especially newer people
frankdugan3
frankdugan3β€’3y ago
In my case, I moved stuff around in an existing app, was kind of hard to figure out which file was missing the API declaration. πŸ™‚ Even though I knew that's what it was. W/ this new error, no-brainer.
ZachDaniel
ZachDanielβ€’3y ago
β›” 🧠

Did you find this page helpful?