Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token as a second param to magic link email #148

Merged
merged 2 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add token as a second param to magic link email
  • Loading branch information
mikker committed Jun 17, 2023
commit 063b0ae503b1e745fffea568fbf258f3ecfc7a75
7 changes: 5 additions & 2 deletions app/mailers/passwordless/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ class Mailer < Passwordless.parent_mailer.constantize

# Sends a magic link (secret token) email.
# @param session [Session] A Passwordless Session
def magic_link(session)
# @param token [String] The token in plaintext. Falls back to `session.token` hoping it
# is still in memory (optional)
def magic_link(session, token = nil)
@session = session
@token = token || session.token

@magic_link = send(:"#{session.authenticatable_type.downcase.pluralize}_token_sign_in_url", session.token)
@magic_link = send(:"#{session.authenticatable_type.downcase.pluralize}_token_sign_in_url", token)

email_field = @session.authenticatable.class.passwordless_email_field
mail(
Expand Down
4 changes: 3 additions & 1 deletion lib/passwordless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def self.digest(token)
mattr_accessor(:sign_out_redirect_path) { "/" }

mattr_accessor(:after_session_save) do
lambda { |session, _request| Mailer.magic_link(session).deliver_now }
lambda do |session, _request|
Mailer.magic_link(session, session.token).deliver_now
end
end
end
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
ActiveSupport::TestCase.fixtures(:all)
end

def Minitest.filter_backtrace(bt)
bt.select { |line| line !~ %r{/gems/} }
end