Skip to content

Commit

Permalink
Add default flash notice on SessionsController#destroy (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianghinda committed Nov 7, 2023
1 parent 7b84234 commit 8855a80
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## Unreleased
# Unreleased

### Added

- Add default flash notice for sign out (#178)

### Fixed

Expand Down
7 changes: 6 additions & 1 deletion app/controllers/passwordless/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ def confirm
# @see ControllerHelpers#sign_out
def destroy
sign_out(authenticatable_class)
redirect_to(passwordless_sign_out_redirect_path, Passwordless.config.redirect_to_response_options.dup)

redirect_to(
passwordless_sign_out_redirect_path,
notice: I18n.t("passwordless.sessions.destroy.signed_out"),
**redirect_to_options
)
end

protected
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ en:
invalid_token: "Token is invalid"
session_expired: "Your session has expired, please sign in again."
token_claimed: "This link has already been used, try requesting the link again"
destroy:
signed_out: "Signed out successfully"
mailer:
sign_in:
subject: "Signing in ✨"
Expand Down
8 changes: 8 additions & 0 deletions test/controllers/passwordless/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,17 @@ class << User

assert_equal 200, status
assert_equal "/", path
assert_match "Signed out successfully", flash[:notice]
assert pwless_session(User).blank?
end

test("DELETE /:passwordless_for/sign_out :: When response options are configured ") do
with_config(redirect_to_response_options: {notice: "my custom notice"}) do
get "/users/sign_out"
assert_match "my custom notice", flash[:notice]
end
end

class Helpers
extend Passwordless::ControllerHelpers
end
Expand Down

0 comments on commit 8855a80

Please sign in to comment.