Skip to content

Fix welcome/password flow bugs#1441

Merged
maebeale merged 9 commits intomainfrom
maebeale/fix-auth-flow-bugs
Mar 28, 2026
Merged

Fix welcome/password flow bugs#1441
maebeale merged 9 commits intomainfrom
maebeale/fix-auth-flow-bugs

Conversation

@maebeale
Copy link
Copy Markdown
Collaborator

@maebeale maebeale commented Mar 27, 2026

What is the goal of this PR and why is this important?

  • Fixes bugs in the confirmation flow that left new users stuck and sent existing users to the wrong place

How did you approach the change?

  • Missing welcome token: When a new user confirms their email but has no welcome token, generates one and redirects to the welcome set-password page instead of leaving them stranded
  • Email change reconfirmation: Uses sign_in_count to distinguish new users (send to welcome flow) from existing users changing their email (send to sign-in with "confirmed" message)
  • Icon fix: fa fa-eyefa-solid fa-eye on welcome page password toggle buttons

UI Testing Checklist

  • Create a user, send invite, click confirmation link → verify redirect to welcome set-password page
  • Change email as an existing user → click confirmation link → verify redirect to sign-in page with "confirmed" message
  • On welcome page, verify eye icon renders on password toggle buttons

🤖 Generated with Claude Code

@maebeale maebeale force-pushed the maebeale/fix-auth-flow-bugs branch from 6ac8763 to a13b2be Compare March 27, 2026 16:33
@maebeale maebeale marked this pull request as ready for review March 27, 2026 16:51
@maebeale maebeale requested a review from jmilljr24 March 27, 2026 16:51
Copy link
Copy Markdown
Collaborator

@jmilljr24 jmilljr24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment regarding the turbo stuff. There's probably other places where turbo can be re-enabled with my suggestion but doesn't have to be part of this PR.

method: :put,
html: { class: "space-y-4" }) do |f| %>
html: { class: "space-y-4" },
data: { turbo: false }) do |f| %>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really try to avoid doing this. While it technically works, it sets a bad pattern of just turning off turbo without finding the root cause and obviously removes all the benefits that turbo provides.

I did some digging and found this config setting we should have.

# config/initializers/devise.rb
Devise.setup do |config|
  # ...
  config.responder.error_status = :unprocessable_entity
  config.responder.redirect_status = :see_other
  # ...
end

I'm wondering if this was part of the issue with some of our flaky specs regarding devise flows.

When the password reset failed validation (short password..) the controller would responded with turbo but status was 200 so the validation errors wouldn't display.

Copy link
Copy Markdown
Collaborator Author

@maebeale maebeale Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooooo, TYYY for finding that config setting! will submit a pr for that.

@maebeale maebeale changed the title Fix password reset and account setup flow bugs Fix welcome/password flows, rescue email errors, upgrade Devise, high-res PDF previews Mar 28, 2026
@maebeale maebeale changed the title Fix welcome/password flows, rescue email errors, upgrade Devise, high-res PDF previews Fix welcome/password flow bugs Mar 28, 2026
@maebeale maebeale force-pushed the maebeale/fix-auth-flow-bugs branch from fa4f9d3 to 026762d Compare March 28, 2026 11:39
maebeale and others added 9 commits March 28, 2026 08:13
- Disable Turbo on password reset form to fix "button does nothing" bug
- Redirect expired welcome token users to password reset instead of
  sign-in dead end (user has no known password)
- Fix Font Awesome icon class on welcome page password toggles

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a new user confirms their email after the welcome token expires,
regenerate the token and send them to the welcome set-password page
instead of the Devise password reset form. Distinguish email-change
reconfirmation (existing users who have signed in) from initial
account setup to avoid routing active users through the welcome flow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Existing users confirming an email change are likely not signed in
when clicking the link, so send them to sign-in with a clear message
rather than bouncing through authenticate_user!.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Justin <16829344+jmilljr24@users.noreply.github.com>
PR #1443 removed token expiry, so the "expired token gets regenerated"
test no longer applies. Updated to verify old tokens are kept as-is.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…n_count

Checking `previous_changes.key?("email")` directly detects whether this
confirmation was an email change, rather than inferring from sign_in_count.
Handles edge cases like legacy ported users (no welcome token, no sign-ins)
and users who happen to have a welcome token while doing an email change.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@maebeale maebeale force-pushed the maebeale/fix-auth-flow-bugs branch from c1ecc8a to 2ede30b Compare March 28, 2026 12:18
def after_confirmation_success(resource)
if resource.welcome_instructions_token.present?
if resource.previous_changes.key?("email")
redirect_to new_user_session_path, notice: "Your email has been confirmed. Please sign in."
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is now true to what we're actually trying to separate -- the email change flow vs the initial welcome flow

@maebeale maebeale merged commit 41432b3 into main Mar 28, 2026
4 of 5 checks passed
@maebeale maebeale deleted the maebeale/fix-auth-flow-bugs branch March 28, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants