diff --git a/README.md b/README.md
index 57336382..8b6afcee 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,7 @@ Default Devise modules included in `Alchemy::User` model
- `:validatable`
- `:timeoutable`
- `:recoverable`
+- `:rememberable`
If you want to add additional modules into the Alchemy user class append them to `Alchemy::Devise.config.devise_modules` in an initializer in your app.
diff --git a/app/views/alchemy/admin/user_sessions/new.html.erb b/app/views/alchemy/admin/user_sessions/new.html.erb
index 82152edf..ff1b51bd 100644
--- a/app/views/alchemy/admin/user_sessions/new.html.erb
+++ b/app/views/alchemy/admin/user_sessions/new.html.erb
@@ -14,6 +14,16 @@
<%= f.input Devise.authentication_keys.first, autofocus: true, required: true,
input_html: {autocomplete: Devise.authentication_keys.first == :email ? "email" : "username"} %>
<%= f.input :password, required: true, input_html: {autocomplete: "current-password"} %>
+ <% if devise_mapping.rememberable? %>
+
+
+
+ <%= f.label :remember_me, class: "checkbox" do %>
+ <%= f.check_box :remember_me, checked: true %>
+ <%= Alchemy.t(:remember_me, scope: 'admin.login', days: Devise.remember_for.in_days.to_i) %>
+ <% end %>
+
+ <% end %>
<%= link_to Alchemy.t('Forgot your password?'), admin_new_password_path %>
diff --git a/config/locales/de.yml b/config/locales/de.yml
new file mode 100644
index 00000000..a03bf368
--- /dev/null
+++ b/config/locales/de.yml
@@ -0,0 +1,5 @@
+de:
+ alchemy:
+ admin:
+ login:
+ remember_me: "Für %{days} Tage angemeldet bleiben"
diff --git a/config/locales/en.yml b/config/locales/en.yml
new file mode 100644
index 00000000..904bdf91
--- /dev/null
+++ b/config/locales/en.yml
@@ -0,0 +1,5 @@
+en:
+ alchemy:
+ admin:
+ login:
+ remember_me: "Remember me for %{days} days"
diff --git a/db/migrate/20251127170649_add_rememberable_column.rb b/db/migrate/20251127170649_add_rememberable_column.rb
new file mode 100644
index 00000000..ad7de7b3
--- /dev/null
+++ b/db/migrate/20251127170649_add_rememberable_column.rb
@@ -0,0 +1,5 @@
+class AddRememberableColumn < ActiveRecord::Migration[7.1]
+ def change
+ add_column :alchemy_users, :remember_created_at, :datetime, if_not_exists: true
+ end
+end
diff --git a/lib/alchemy/devise/configuration.rb b/lib/alchemy/devise/configuration.rb
index a4fbc803..ed3407aa 100644
--- a/lib/alchemy/devise/configuration.rb
+++ b/lib/alchemy/devise/configuration.rb
@@ -16,7 +16,8 @@ class Configuration < Alchemy::Configuration
# :trackable,
# :validatable,
# :timeoutable,
- # :recoverable
+ # :recoverable,
+ # :rememberable
# ]
#
# If you want to add additional modules into the Alchemy user class append
@@ -37,7 +38,8 @@ class Configuration < Alchemy::Configuration
:trackable,
:validatable,
:timeoutable,
- :recoverable
+ :recoverable,
+ :rememberable
]
end
end
diff --git a/spec/features/login_feature_spec.rb b/spec/features/login_feature_spec.rb
index 5a52bdbd..6e32daa8 100644
--- a/spec/features/login_feature_spec.rb
+++ b/spec/features/login_feature_spec.rb
@@ -57,5 +57,29 @@
Devise.authentication_keys = default_key
end
end
+
+ context "with rememberable Devise module enabled" do
+ before do
+ allow_any_instance_of(Devise::Mapping).to receive(:rememberable?).and_return(true)
+ end
+
+ it "displays a remember me checkbox" do
+ visit "/admin/login"
+ expect(page).to have_css("label input#user_remember_me[checked]")
+ expect(page).to have_content("Remember me for 14 days")
+ end
+ end
+
+ context "with rememberable Devise module disabled" do
+ before do
+ allow_any_instance_of(Devise::Mapping).to receive(:rememberable?).and_return(false)
+ end
+
+ it "does not display a remember me checkbox" do
+ visit "/admin/login"
+ expect(page).to have_css(":not(:has(input#user_remember_me))")
+ expect(page).to_not have_content("Remember me for 14 days")
+ end
+ end
end
end