I am using ash_authentication with the “password” strategy, so I have an auto-generated User
module with a register_with_password
create action (see below).
I also have a code interface function in the Accounts
module that uses this action:
resource Proj.Accounts.User do
define :register_user, action: :register_with_password
end
This results in six new functions being available, register_user/0
, register_user/1
, and register_user/2
plus register_user!/0
, register_user!/1
, and register_user!/2
.
However, the /0 versions don’t actually work - the register_with_password
action requires a map with e-mail, password, and password confirmation to be passed as the first argument.
Is there a way to rewrite my code interface function so only the /1 and /2 versions are generated?
(This not much of a problem, of course, I’d just like no know if it is possible)
register_with_password action:
create :register_with_password do
description "Register a new user with a email and password."
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
# 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
# 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