Accessing the user from the mailer template
Hiya 👋🏻 I'm a bit stumped on something: is there currently a way to access the user/authenticatable object from within the mailer template?
My use case is that I'd like to only send the code (and not the link) for some organisations, because including the link can significantly slow down email delivery as their email scanning software spends time previewing any links in external emails.
But a simpler use case would be wanting to greet the user in the email template ("Hi <%= @user.name %>, click here to sign in")
Judging from Mailer.rb only the @token and @magic_link are available from the template. Both of these are strings, and there doesn't appear to be a way to get back to the session/authenticatable without monkey patching the library's Mailer class.
Any ideas?
You can create your own mailer and use that. No need to patch
Passwordless.configure do |config|
config.after_session_save = lambda do |session, request|
# Default behavior is
# Passwordless::Mailer.sign_in(session, session.token).deliver_now
MyMailer.sign_in(session, session.token).deliver_now
end
end
You can access the user through session. Confusingly named session it is actually the Passwordless::Sesssion record.