Class: SolidLog::UI::BaseController
- Inherits:
-
Object
- Object
- SolidLog::UI::BaseController
- Includes:
- Turbo::Streams::TurboStreamsTagBuilder
- Defined in:
- app/controllers/solid_log/ui/base_controller.rb
Direct Known Subclasses
DashboardController, EntriesController, FieldsController, StreamsController, TimelinesController, TokensController
Instance Method Summary collapse
-
#authenticate_user! ⇒ Object
Override this method in your host application to implement custom authentication.
Instance Method Details
#authenticate_user! ⇒ Object
Override this method in your host application to implement custom authentication
Example configurations in config/initializers/solid_log_ui.rb:
- Using a Proc/Lambda:
SolidLog::UI.configure do |config|
config.authentication_method = ->(controller) {
controller.redirect_to controller.root_path unless controller.current_user&.admin?
}
end
- Using a method name:
SolidLog::UI.configure do |config|
config.authentication_method = :require_admin
end
class ApplicationController
def require_admin
redirect_to root_path unless current_user&.admin?
end
end
- Using basic auth:
SolidLog::UI.configure do |config|
config.authentication_method = :basic
end
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/solid_log/ui/base_controller.rb', line 54 def authenticate_user! config = SolidLog::UI.configuration auth_method = config.authentication_method case auth_method when :none # No authentication required true when :basic authenticate_or_request_with_http_basic("SolidLog") do |username, password| authenticate_with_basic_auth(username, password) end when Proc # Call the proc in the controller's context instance_exec(&auth_method) when Symbol # Call the named method on the controller if respond_to?(auth_method, true) send(auth_method) else raise NoMethodError, "Authentication method '#{auth_method}' not defined. Define it in your ApplicationController or BaseController." end else render plain: "Invalid authentication configuration", status: :unauthorized false end end |