Skip to content

Commit

Permalink
Fix passwordless_sign_in bugs (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
yshmarov authored Nov 9, 2023
1 parent a7891a8 commit cd6ec4f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixed

- Fixed a bug in `passwordless_sign_in` (#179)

## 1.1.0

### Changed
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/passwordless/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def sign_in(session, token = nil)
controller: "passwordless/sessions",
action: "confirm",
id: session.identifier,
token: token,
token: @token,
authenticatable: "user",
resource: "users"
}
Expand Down
3 changes: 2 additions & 1 deletion app/views/passwordless/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<%= f.label email_field_name,
t("passwordless.sessions.new.email.label"),
for: "passwordless_#{email_field}" %>
<%= text_field_tag email_field_name,
<%= email_field_tag email_field_name,
params.fetch(email_field_name, nil),
required: true,
autofocus: true,
placeholder: t("passwordless.sessions.new.email.placeholder") %>
<%= f.submit t("passwordless.sessions.new.submit") %>
<% end %>
3 changes: 3 additions & 0 deletions docs/upgrading_to_1_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class UpgradePasswordless < ActiveRecord::Migration[7.0]
add_column(:passwordless_sessions, :token_digest, :string)
add_index(:passwordless_sessions, :token_digest)
remove_column(:passwordless_sessions, :token, :string, null: false)
# UUID
add_column(:passwordless_sessions, :identifier, :string)
add_index(:passwordless_sessions, :identifier, unique: true)

# Remove PII
remove_column(:passwordless_sessions, :user_agent, :string, null: false)
Expand Down
2 changes: 1 addition & 1 deletion lib/passwordless/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def passwordless_sign_in(resource)
{
controller: "passwordless/sessions",
action: "confirm",
id: session.id,
id: session.to_param,
token: session.token,
authenticatable: cls.model_name.singular,
resource: cls.model_name.to_s.tableize
Expand Down
4 changes: 4 additions & 0 deletions test/mailers/passwordless/mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ class Passwordless::MailerTest < ActionMailer::TestCase
assert_match "Signing in ✨", email.subject
assert_match /sign in: hello\n/, email.body.to_s
assert_match %r{/sign_in/#{session.identifier}/hello}, email.body.to_s

session = Passwordless::Session.create!(authenticatable: user)
email = Passwordless::Mailer.sign_in(session)
assert_equal [user.email], email.to
end
end
2 changes: 1 addition & 1 deletion test/passwordless/test_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PasswordlessTestHelpersTest < ActiveSupport::TestCase
assert 1, Session.count
assert alice, Session.last!.authenticatable
assert_match(
%r{^http://.*/users/sign_in/[a-z0-9]+/[a-z0-9]+}i,
%r{^http://.*/users/sign_in/[a-z0-9-]+/[a-z0-9]+}i,
controller.actions.first.last.first
)

Expand Down

0 comments on commit cd6ec4f

Please sign in to comment.