Skip to content

Commit

Permalink
locale to support scoped routes mikker#206
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaskundig committed Feb 13, 2024
1 parent d69f28b commit 91c8772
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/controllers/passwordless/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def create
Passwordless.context.path_for(
@session,
id: @session.to_param,
action: "show"
action: "show",
**locale_options
),
flash: {notice: I18n.t("passwordless.sessions.create.email_sent")}
)
Expand Down Expand Up @@ -250,5 +251,10 @@ def passwordless_session
def passwordless_session_params
params.require(:passwordless).permit(:token, authenticatable_class.passwordless_email_field)
end

def locale_options
locale = params[:locale]
locale ? { locale: locale } : {}
end
end
end
3 changes: 2 additions & 1 deletion app/mailers/passwordless/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ class Mailer < Passwordless.config.parent_mailer.constantize
# @param session [Session] An instance of Passwordless::Session
# @param token [String] The token in plaintext. Falls back to `session.token` hoping it
# is still in memory (optional)
def sign_in(session, token = nil)
def sign_in(session, token = nil, url_options = {})
@token = token || session.token

@magic_link = Passwordless.context.url_for(
session,
action: "confirm",
id: session.to_param,
token: @token,
**url_options,
**default_url_options
)

Expand Down
6 changes: 4 additions & 2 deletions lib/passwordless/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ class Configuration
option :sign_out_redirect_path, default: "/"
option(
:after_session_save,
default: lambda do |session, _request|
Mailer.sign_in(session, session.token).deliver_now
default: lambda do |session, request|
locale = request.params[:locale]
url_options = locale ? { locale: locale } : {}
Mailer.sign_in(session, session.token, url_options).deliver_now
end
)

Expand Down

0 comments on commit 91c8772

Please sign in to comment.