AshAuthentication Auth0 error after setup instructions

I followed the AshAuthentication Auth0 guide

My understanding is that it needs to be followed after following the AshAuthenticationPhoenix guide.

The guide did not say which code to delete.

I deleted the hashed password code, because I will no longer use that.

I also deleted the Token resource and all references to it, because my understanding was that it’s purpose is to be a password reset token, which my app will no longer handle.

This is the PR I ended up with

Password auth works on the main branch, so this should just be the diff from password auth to Auth0.

Right now I get redirected to Auth0, redirected back to my app, but an error gets rendered on the redirect url.

Here is the stack trace:

Unknown Error

Context: resolving data on perform Red.Accounts.User.register_with_auth0
* Context: resolving data on perform Red.Accounts.User.register_with_auth0

** (ArgumentError) No identity found for Red.Accounts.User called :email
  (ash 2.14.20) lib/ash/actions/create/create.ex:323: anonymous fn/11 in Ash.Actions.Create.as_requests/5
  (ash 2.14.20) lib/ash/engine/request.ex:1111: Ash.Engine.Request.do_try_resolve_local/4
  (ash 2.14.20) lib/ash/engine/request.ex:284: Ash.Engine.Request.do_next/1
  (ash 2.14.20) lib/ash/engine/request.ex:213:
  (ash 2.14.20) lib/ash/engine/engine.ex:712: Ash.Engine.advance_request/2
  (ash 2.14.20) lib/ash/engine/engine.ex:637: Ash.Engine.fully_advance_request/2
  (ash 2.14.20) lib/ash/engine/engine.ex:578: Ash.Engine.do_run_iteration/2
  (elixir 1.15.4) lib/enum.ex:2510: Enum."-reduce/3-lists^foldl/2-0-"/3
  (ash 2.14.20) lib/ash/engine/engine.ex:307: Ash.Engine.run_to_completion/1
  (ash 2.14.20) lib/ash/engine/engine.ex:252: Ash.Engine.do_run/2
  (ash 2.14.20) lib/ash/engine/engine.ex:148:
  (ash 2.14.20) lib/ash/actions/create/create.ex:111: Ash.Actions.Create.do_run/4
  (ash 2.14.20) lib/ash/actions/create/create.ex:38:
  (red 0.1.0) lib/red/accounts/accounts.ex:1: Red.Accounts.create/2
  (ash_authentication 3.11.15) lib/ash_authentication/strategies/oauth2/plug.ex:64: AshAuthentication.Strategy.OAuth2.Plug.callback/2
  (ash_authentication 3.11.15) lib/ash_authentication/plug/dispatcher.ex:29:
  (phoenix 1.7.7) lib/phoenix/router.ex:430: Phoenix.Router.__call__/5
  (red 0.1.0) lib/red_web/endpoint.ex:1: RedWeb.Endpoint.plug_builder_call/2
  (red 0.1.0) deps/plug/lib/plug/debugger.ex:136: RedWeb.Endpoint."call (overridable 3)"/2
  (red 0.1.0) lib/red_web/endpoint.ex:1:

We should definitely make the error for this include more context. The action is referring to an :identity called :email, but the identity that you have on your resource is called :unique_email.

upsert_identity :email

You’d want to change that to

upsert_identity :unique_email

EDIT: the line: Auth0 almost working 🤷‍♂️ by dewetblomerus · Pull Request #2 · dewetblomerus/red · GitHub

That did it @zachdaniel :heart:

Now I can sign in and out with Auth0! :partying_face:

Here is the resulting diff if anyone is interested.

1 Like

The error makes perfect sense now that I see the fix, but it would be difficult for someone new to Ash to realize that. I just wrongly assumed upserting with email must be right because there is an email column in the DB.

Yeah, absolutely. It should say something like:

No identity found for Red.Accounts.User called :email.

Resource.action required this identity due to using `upsert_identity :email`

Available identities:

* `identity` ...