dewetblomerus
This is not important, I’m just curious about how it would be done.
The updated_at field on my User gets bumped on every login, even if no fields changed. Auth0 already saves all the history about successful and unsuccessful logins, so I only want updated_at to be bumped when one of the fields for the User resource is being changed to a different value.
I followed this guide and then made some changes and eded up with the following action:
create :register_with_auth0 do
argument :user_info, :map, allow_nil?: false
argument :oauth_tokens, :map, allow_nil?: false
upsert? true
upsert_identity :unique_auth0_id
# Required if you have token generation enabled.
change AshAuthentication.GenerateTokenChange
# Required if you have the `identity_resource` configuration enabled.
change AshAuthentication.Strategy.OAuth2.IdentityChange
change fn changeset, _ ->
user_info = Ash.Changeset.get_argument(changeset, :user_info)
changes = %{
"email" => Map.get(user_info, "email"),
"auth0_id" => Map.get(user_info, "sub")
}
Ash.Changeset.change_attributes(
changeset,
changes
)
end
end
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
jimsynz
If I’m reading the docs correctly when
upsert_fieldsis empty then all fields except those with defaults are set on conflict. This would lead me to believe that you shouldn’t be seeing the updated_at changing if there are no other changes. Is that not the case?dewetblomerus
I just confirmed,
updated_atis definitely getting updated tonow()on every login.I do not see
upsert_fieldsin my code or in theAsh.Changesetso I can not make sure if it is empty or not.There are for-sure no other fields changing, just the
updated_at.Here is the changeset I am returning from the
register_with_auth0change:jimsynz
Thanks for the confirmation. I believe this could be solved by #760. Keep an eye on that issue for updates.
zachdaniel
Yes, so since it’s a create or update, each login becomes an update. You can use the new
{:replace_all_except, [:updated_at]}option to prevent that behavior.dewetblomerus
Thanks a lot for remembering and circling back.
I might have found an error scenario that needs some work.
I updated to the following:
Then I tried this:
upsert_fields { :replace_all_except, [:updated_at] }I also tried this:
I also tried
upsert_fields :replace_allAnd since I was on a roll, I tried the following:
All of the above yielded the same result. I get an error at login, but there is no error in the logs, just a
rollback. Here are the logs:Link to my entire user
zachdaniel
Can you try submitting the action in iex with that
upsert_fieldsset? I’m not sure what the issue is currently.dewetblomerus
While trying to get the output for this, I got stuck with something I have gotten stuck with a few times while using Ash. I am calling an Ash function with the wrong arguments, and the error message is trying to tell me something, but I am unable to translate the error message into how to fix it.
Here is what I tried:
When I run this, I get the following error:
I tried to put
email: emailas part of theparamsmap or theoptslist arguments toAsh.Changeset.for_updatebut nothing I tried changed the error.changeset.errorsis as follows:zachdaniel
This seems strange. Is this your own action? Do you have a change or something in the action attempting to set the email based on some input, but setting it to
nil?dewetblomerus
This is my current action:
It is still very close to what I had after following this guide: https://ash-hq.org/docs/guides/ash_authentication/latest/tutorials/auth0-quickstart
dewetblomerus
I am seeing something else in the changeset that might help:
Under
attributes, it only has a name, but I passed in a name and email.This code works 100% for signup and login.