changes in generic action
Hi this is the jist of what what to do for my specific use case I know it's not possible: but there must be someway to do this by for example: making the changes runs or the action a create etc.
I'm stumped right now so any advice welcome : )
action :request_magic_link do
argument :email, :ci_string do
allow_nil? false
end
change Wildflower.Accounts.AbortIfEmailRecentlySent
change Wildflower.Accounts.AbortIfUserExists
run AshAuthentication.Strategy.MagicLink.Request
end
9 Replies
could you explain in words what you want to achive?
AFAIS you want to send a magic link to user but only if it wasn't sent recently and user does not already exist - correct?
also to note:
When registration is enabled, signing in with magic is a create action that upserts the user by email. This allows a user who does not exist to request a magic link and sign up with one action.don't know if you enabled this, but you can use magic link for registration and login. so idg why you want the abort functionality
Hey Ken essentailly I want to only send the magic link email if hasn't been sent recently (my change AbortIfEmailRecentlySent was implementing a timeout based on the email identity) and I also want to disable magic links for signing in only allowing it for registration.
def handle_event("submit", %{"user" => %{"email" => email} = params}, socket) do
with :ok <- abort_if_email_recently_sent(email),
{:error, _error} <- MyApp.Accounts.get_byemail(email) do
case dbg(
Form.submit(socket.assigns.form,
params: params
)
) do
{:ok, } ->
this is the solution I have now but it would be nice I could run this all in the action which could be single visit to the db.
You can't add changes to generic actions, all the logic has to live in the run function
can run mutiple generic actions via the run clause in a single action?
action :request_magic_link do
argument :email, :ci_string do
allow_nil? false
end
run Wildflower.Accounts.AbortIfEmailRecentlySent
run Wildflower.Accounts.AbortIfUserExists
run AshAuthentication.Strategy.MagicLink.Request
end
I'm imaging something like this
I don't want to make changes to the code which came with the library and my changes don't feel large enough to warrant a new strategry. Any work rounds you can think of would be great?
A
Thanks. Are thing1() and thing2() regular elixir functions? What would I need to return to abort that whole action and stop it progressing to the next thing/magiclink.request? Lastly, if I set the trasnaction flag would that still work here?
Yeah that was just pseudocode
you can do anything you like
and yes the transaction flag would wrap it all in a transaction
Okay awesome thanks!
aha I thought it was the run macro's dsl
Understandable 😆