AshAuthentication require confirmation not working

I am going through the Confirmation Tutorial, and even though I have added require_confirmed_with to the password strategy block, I can still log in before visiting the confirmation URL in the email. Worth noting that I started adding AshAuthentication to my application before the Igniter installers were added, so my resources may be missing some optional-but-recommended blocks that the installers add.
Solution:
Okay, fix released, docs updated
Jump to solution
17 Replies
aidalgol
aidalgolOP•4mo ago
I posted this 1 minute before the release-day announcements, so I'll go update my deps now. 😆 Now running latest version of all ash deps. Same issue.
ZachDaniel
ZachDaniel•4mo ago
What does your code look like? Like the DSL I mean What did you set the value of :require_confirmed_with to?
aidalgol
aidalgolOP•4mo ago
I attached the source files for my user and token resources. They show up inline on the web client, but it might be more of a pain on mobile.
ZachDaniel
ZachDaniel•4mo ago
Ah, I see Um... hm. Does the user in question have the confirmation attribute set? Or is it nil? And you recompiled etc to make sure it's not like a build issue or something?
aidalgol
aidalgolOP•4mo ago
It's set to nil. I don't think I tried recompiling after running the ash.codegen and ash.reset mix tasks. I'll try that now.
ZachDaniel
ZachDaniel•4mo ago
I'm...not actually sure that code has ever been doing the right thing on registration. I suspect people were solving for it by not placing the user in the session on registration
ZachDaniel
ZachDaniel•4mo ago
That needs to do the confirmation logic that sign in does. @jart ^ I think most people are rolling their own confirmation requirements with a plug actually TBH It's a better UX when you let the user be signed in, but take them to a page asking them to confirm their account That's likely why no one noticed
aidalgol
aidalgolOP•4mo ago
Ah
ZachDaniel
ZachDaniel•4mo ago
I'll fix that behavior though. Nope, I won't 😄 I'll just have to update the docs Essentially, post-registration you still need to be able to get the user back who just registered So we can't return an error
aidalgol
aidalgolOP•4mo ago
It also seems app-dependant what you want to do if the user is not confirmed.
ZachDaniel
ZachDaniel•4mo ago
so its up to you in your success callback to decide whether or not to put the user into the session This is now explained 😄 Thanks for bringing it up. You know it needs docs when even I'm confused about how its supposed to work 😜
aidalgol
aidalgolOP•4mo ago
Note that, on registration, the user will still be provided to your success callback in your AuthController (when using AshAuthenticationPhoenix). It is your responsibility to determine what to do post-registration. This typically means modifying the default not to call store_in_session if the activity is for registration.
Not sure that will work. From my app's log (messages from AshPostgres omitted),
[debug] HANDLE EVENT "submit" in AshAuthentication.Phoenix.SignInLive
Component: AshAuthentication.Phoenix.Components.Password.RegisterForm
Parameters: %{"_csrf_token" => "fGQYcgUABFgqISw_NSEnPSh9PSAlIRoN90pJkfHokixfaDKnpLzcFHwF", "user" => %{"email" => "dave@example.net", "password" => "[FILTERED]", "password_confirmation" => "[FILTERED]"}}
[debug] Replied in 284ms
[info] GET /auth/user/password/sign_in_with_token
[debug] Processing with AshAuthentication.Phoenix.StrategyRouter
Parameters: %{"token" => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ-PiA0LjkiLCJleHAiOjE3NTE1MTI5MTcsImlhdCI6MTc1MDMwMzMxNywiaXNzIjoiQXNoQXV0aGVudGljYXRpb24gdjQuOS4yIiwianRpIjoiMzE1NTc2MDk1ZzFiMWh0OWE4MDAwMWcyIiwibmJmIjoxNzUwMzAzMzE3LCJwdXJwb3NlIjoic2lnbl9pbiIsInN1YiI6InVzZXI_aWQ9ZWExMzFhM2QtOGUzNC00MTI1LWEwMDAtNjA5NzkzYzQ5NDIzIn0.6XoYGH6trz7GQ6m9VNXbLqb4DvGIYHmi4LIniTCd9cc"}
Pipelines: [:browser]
[debug] [auth: :success, activity: {:password, :sign_in_with_token}]
[info] Sent 302 in 30ms
[info] GET /
[debug] HANDLE EVENT "submit" in AshAuthentication.Phoenix.SignInLive
Component: AshAuthentication.Phoenix.Components.Password.RegisterForm
Parameters: %{"_csrf_token" => "fGQYcgUABFgqISw_NSEnPSh9PSAlIRoN90pJkfHokixfaDKnpLzcFHwF", "user" => %{"email" => "dave@example.net", "password" => "[FILTERED]", "password_confirmation" => "[FILTERED]"}}
[debug] Replied in 284ms
[info] GET /auth/user/password/sign_in_with_token
[debug] Processing with AshAuthentication.Phoenix.StrategyRouter
Parameters: %{"token" => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ-PiA0LjkiLCJleHAiOjE3NTE1MTI5MTcsImlhdCI6MTc1MDMwMzMxNywiaXNzIjoiQXNoQXV0aGVudGljYXRpb24gdjQuOS4yIiwianRpIjoiMzE1NTc2MDk1ZzFiMWh0OWE4MDAwMWcyIiwibmJmIjoxNzUwMzAzMzE3LCJwdXJwb3NlIjoic2lnbl9pbiIsInN1YiI6InVzZXI_aWQ9ZWExMzFhM2QtOGUzNC00MTI1LWEwMDAtNjA5NzkzYzQ5NDIzIn0.6XoYGH6trz7GQ6m9VNXbLqb4DvGIYHmi4LIniTCd9cc"}
Pipelines: [:browser]
[debug] [auth: :success, activity: {:password, :sign_in_with_token}]
[info] Sent 302 in 30ms
[info] GET /
(The line [debug] [auth: :success, activity: {:password, :sign_in_with_token}] is from my AuthController.) I think you'd still do the check in AuthController, but you would have to look at the user record's confirmed_at attribute, rather than the activity parameter. Which would also cover both registering and signing-in paths.
ZachDaniel
ZachDaniel•4mo ago
Hm...yeah. I guess when you have sign in tokens enabled, it doesn't tell you if the user just registered or not 😅 Will think on it Okay, @aidalgol I think I might see whats going on. Do you have sign_in_tokens_enabled?
Solution
ZachDaniel
ZachDaniel•4mo ago
Okay, fix released, docs updated
aidalgol
aidalgolOP•4mo ago
I haven't enabled it explicitly anywhere. Is that an ash config parameter, or something I'd set on the resource? Never mind, I found it in the docs. I should really finish my morning coffee before responding to messages. 🫠 So yes, it is enabled, because it defaults to true.
aidalgol
aidalgolOP•4mo ago
Thanks for your help on this.

Did you find this page helpful?