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,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
Hello everyone! :waving_hand:
I’d like to share JSONSchex, a JSON Schema Draft 2020-12 library for Elixir focused on correctness, repeat...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











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.