Skip to content

Instantly share code, notes, and snippets.

@vesan
Forked from janko/application_controller.rb
Created November 7, 2023 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vesan/5f2ceeaeb82929950cee68cd4c96d770 to your computer and use it in GitHub Desktop.
Save vesan/5f2ceeaeb82929950cee68cd4c96d770 to your computer and use it in GitHub Desktop.
Implementing Devise groups in Rodauth
class ApplicationController < ActionController:Base
extend ControllerMacros
end
module ControllerMacros
def rodauth_group(group_name, configuration_names)
define_method(:"authenticate_#{group_name}!") do
unless send(:"#{group_name}_authenticated?")
configuration_names.each do |name|
rodauth(name).require_authenication
end
end
end
define_method(:"#{group_name}_authenticated?") do
configuration_names.any? do |name|
rodauth(name).authenticated?
end
end
define_method(:"current_#{group_name}") do
send(:"current_#{group_name.to_s.pluralize}").first
end
define_method(:"current_#{group_name.to_s.pluralize}") do
configuration_names.map { |name| rodauth(name).rails_account }.compact
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment