zer3f
Hi,
First of all sorry, i don’t know how to put this scenario as title. I am working with forms contains this scenario.
- Create company with user. This one has manage_relationships which
has_manywith the:usersrelationship like this:
create :create_company_with_user do
accept [:name, :registration_number]
# argument :generate_hash?, :boolean, default: false
argument :user, :map, allow_nil?: false
# change {Mgx.Company.Changes.RegistrationNumber, generate_hash?: :generate_hash?}
change manage_relationship(:user, :users, type: :create)
end
- Now for the user
primary actionis this which haspersonal_informationhashas_onerelationship with theuserlike this(From Ash authentication, I made another action)
create :register_with_password_with_personal_details do
description "Register a new user with a email and password and personal information"
primary? true
argument :email, :ci_string do
allow_nil? false
end
argument :password, :string do
description "The proposed password for the user, in plain text."
allow_nil? false
constraints min_length: 8
sensitive? true
end
argument :password_confirmation, :string do
description "The proposed password for the user (again), in plain text."
allow_nil? false
sensitive? true
end
argument :personal_information, :map do
allow_nil? false
end
validate match(:email, ~r/@/), message: "must be a valid email"
# Sets the email from the argument
change set_attribute(:email, arg(:email))
# Hashes the provided password
change AshAuthentication.Strategy.Password.HashPasswordChange
# Generates an authentication token for the user
change AshAuthentication.GenerateTokenChange
# Manage the relationship with the personal information
change manage_relationship(:personal_information, :personal_information,
type: :direct_control
)
# validates that the password matches the confirmation
validate AshAuthentication.Strategy.Password.PasswordConfirmationValidation
metadata :token, :string do
description "A JWT that can be used to authenticate the user."
allow_nil? false
end
end
So my relationships are:
- company
has_manyusers - user
has_onepersonal_information
I tried to mount the the form like this:
def mount(_params, _session, socket) do
form =
Mgx.Company.form_to_create_company_with_user(forms: [auto?: true])
|> AshPhoenix.Form.add_form([:user])
|> AshPhoenix.Form.add_form([:user, :personal_information])
{:ok,
assign(socket,
form: to_form(form)
)}
end
Immediately I get this warning when mounted and registration fails when submitted:
warning] Unhandled error in form submission for Mgx.Accounts.User.register_with_password_with_personal_details
This error was unhandled because Ash.Error.Framework.AssumptionFailed does not implement the `AshPhoenix.FormData.Error` protocol.
** (Ash.Error.Framework.AssumptionFailed) Assumption failed: Action does not correlate with an authentication strategy
This should not be possible, please report a detailed bug at:
https://github.com/ash-project/ash/issues/new?assignees=&labels=bug%2C+needs+review&template=bug_report.md&title=
[warning] Unhandled error in form submission for Mgx.Accounts.User.register_with_password_with_personal_details
This error was unhandled because Ash.Error.Framework.AssumptionFailed does not implement the `AshPhoenix.FormData.Error` protocol.
** (Ash.Error.Framework.AssumptionFailed) Assumption failed: Action does not correlate with an authentication strategy
This should not be possible, please report a detailed bug at:
https://github.com/ash-project/ash/issues/new?assignees=&labels=bug%2C+needs+review&template=bug_report.md&title=
This form successfully render though:
<.simple_form for={@form} phx-change="validate" phx-submit="save">
<.input field={@form[:name]} label="Company Name" />
<.input field={@form[:registration_number]} label="Company Registration Number" />
<.inputs_for :let={user} field={@form[:user]}>
<.input field={user[:email]} label="Email" type="email" />
<.inputs_for :let={personal_information} field={user[:personal_information]}>
<.input field={personal_information[:first_name]} label="First Name" />
<.input field={personal_information[:last_name]} label="Last Name" />
<.input field={personal_information[:country_code]} label="Country Code" />
<.input field={personal_information[:phone_number]} label="Phone Number" />
</.inputs_for>
</.inputs_for>
<:actions>
<.button class="w-full bg-[#262262] hover:bg-[#0C0944]">Register</.button>
</:actions>
</.simple_form>
Side Note: If I remove the manage_relationship of personal_information in the user, I can successfully submit the form. with company and user. while removing add_form([:user, :personal_information]
Maybe mount function I am assigning wrong? As always any help would be greatly appreciated thank you.
This is total Form I see when I submit:
[error] Registration failed: %Phoenix.HTML.Form{
source: #AshPhoenix.Form<
resource: Mgx.Company.CompanyInformation,
action: :create_company_with_user,
type: :create,
params: %{
"name" => "Hatfield and Vega Associates",
"registration_number" => "Gamble Cotton Trading",
"user" => %{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_email,email,personal_information",
"email" => "rocysog@mailinator.com",
"password" => "password",
"password_confirmation" => "password",
"personal_information" => %{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_country_code,_unused_first_name,_unused_last_name,_unused_phone_number,country_code,first_name,last_name,phone_number",
"country_code" => "Tenetur enim ipsam q",
"first_name" => "Troy",
"last_name" => "Lewis",
"phone_number" => "+1 (358) 257-3731"
}
}
},
source: #Ash.Changeset<
domain: Mgx.Company,
action_type: :create,
action: :create_company_with_user,
attributes: %{
name: "Hatfield and Vega Associates",
status: :pending,
registration_number: "Gamble Cotton Trading"
},
relationships: %{
users: [
{[
%{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_email,email,personal_information",
"email" => "rocysog@mailinator.com",
"password" => "password",
"password_confirmation" => "password",
"personal_information" => %{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_country_code,_unused_first_name,_unused_last_name,_unused_phone_number,country_code,first_name,last_name,phone_number",
"country_code" => "Tenetur enim ipsam q",
"first_name" => "Troy",
"last_name" => "Lewis",
"phone_number" => "+1 (358) 257-3731"
}
}
],
[
ignore?: false,
on_missing: :ignore,
on_match: :ignore,
on_lookup: :ignore,
on_no_match: :create,
eager_validate_with: false,
authorize?: true,
meta: [id: :user],
type: :create
]}
]
},
arguments: %{
user: %{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_email,email,personal_information",
"email" => "rocysog@mailinator.com",
"password" => "password",
"password_confirmation" => "password",
"personal_information" => %{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_country_code,_unused_first_name,_unused_last_name,_unused_phone_number,country_code,first_name,last_name,phone_number",
"country_code" => "Tenetur enim ipsam q",
"first_name" => "Troy",
"last_name" => "Lewis",
"phone_number" => "+1 (358) 257-3731"
}
}
},
errors: [],
data: #Mgx.Company.CompanyInformation<
company_documents: #Ash.NotLoaded<:relationship, field: :company_documents>,
company_tdls: #Ash.NotLoaded<:relationship, field: :company_tdls>,
company_gasx_profile: #Ash.NotLoaded<:relationship, field: :company_gasx_profile>,
company_lngx_profile: #Ash.NotLoaded<:relationship, field: :company_lngx_profile>,
billing_address: #Ash.NotLoaded<:relationship, field: :billing_address>,
business_address: #Ash.NotLoaded<:relationship, field: :business_address>,
users: #Ash.NotLoaded<:relationship, field: :users>,
__meta__: #Ecto.Schema.Metadata<:built, "company_informations">,
id: nil,
name: nil,
registration_number: nil,
website: nil,
subscription_plan: nil,
status: :pending,
last_registration_submitted_at: nil,
inserted_at: nil,
updated_at: nil,
aggregates: %{},
calculations: %{},
...
>,
valid?: true
>,
name: "form",
data: nil,
form_keys: [
user: [
create_action: :register_with_password_with_personal_details,
create_resource: Mgx.Accounts.User,
type: :single,
forms: [
personal_information: [
type: :single,
forms: [],
sparse?: false,
managed_relationship: {Mgx.Accounts.User, :personal_information,
[
on_lookup: :ignore,
on_no_match: {:create, :create},
on_match: {:update, :update},
on_missing: {:destroy, :destroy},
type: :direct_control
]},
must_load?: false,
updater: #Function<36.69732248/1 in AshPhoenix.Form.Auto.related/3>
]
],
sparse?: false,
managed_relationship: {Mgx.Company.CompanyInformation, :users,
[
on_missing: :ignore,
on_lookup: :ignore,
on_no_match: {:create, :register_with_password_with_personal_details},
on_match: :ignore,
type: :create
]},
must_load?: false
]
],
forms: %{
user: #AshPhoenix.Form<
resource: Mgx.Accounts.User,
action: :register_with_password_with_personal_details,
type: :create,
params: %{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_email,email,personal_information",
"email" => "rocysog@mailinator.com",
"password" => "password",
"password_confirmation" => "password",
"personal_information" => %{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_country_code,_unused_first_name,_unused_last_name,_unused_phone_number,country_code,first_name,last_name,phone_number",
"country_code" => "Tenetur enim ipsam q",
"first_name" => "Troy",
"last_name" => "Lewis",
"phone_number" => "+1 (358) 257-3731"
}
},
source: #Ash.Changeset<
domain: Mgx.Accounts,
action_type: :create,
action: :register_with_password_with_personal_details,
attributes: %{
role: :company_admin,
email: #Ash.CiString<"rocysog@mailinator.com">
},
relationships: %{
personal_information: [
{[
%{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_country_code,_unused_first_name,_unused_last_name,_unused_phone_number,country_code,first_name,last_name,phone_number",
"country_code" => "Tenetur enim ipsam q",
"first_name" => "Troy",
"last_name" => "Lewis",
"phone_number" => "+1 (358) 257-3731"
}
],
[
ignore?: false,
on_missing: :destroy,
on_match: :update,
on_lookup: :ignore,
on_no_match: :create,
eager_validate_with: false,
authorize?: true,
meta: [id: :personal_information],
type: :direct_control
]}
]
},
arguments: %{
(truncated)
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Other Trending Topics
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
Those changes from ash authentication rely on knowing which authentication strategy contains the relevant configuration. by default it comes from the action name, but if you make a custom action you need to tell it still:
change set_context(%{strategy_name: :password})that should go above the other changes.zer3f
It works. Thanks again Zach