isAdmin trick

This commit is contained in:
2026-07-29 13:27:39 +02:00
parent beac29c851
commit a170eff37a
2 changed files with 21 additions and 1 deletions
@@ -0,0 +1,20 @@
# Set a JS-readable cookie when an admin signs in/out.
# Devise's remember_admin_user_token cookie is HttpOnly,
# so the frontend cannot read it. This non-HttpOnly cookie
# lets the frontend show/hide the Admin menu link.
Rails.application.config.to_prepare do
ApplicationController.class_eval do
after_action :sync_admin_cookie
private
def sync_admin_cookie
if current_admin_user
cookies[:is_admin] = { value: "1", httponly: false, same_site: :lax, path: "/" }
elsif cookies[:is_admin]
cookies.delete(:is_admin, path: "/")
end
end
end
end