Torque Admin treats authentication as a first-class routing concern rather than an afterthought. Every route generated by the admin engine carries anDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/crashtech/torque-admin/llms.txt
Use this file to discover all available pages before exploring further.
authenticated annotation that controllers and middleware can inspect, and the engine ships with built-in support for three authentication providers so you can wire in your existing auth stack with minimal boilerplate.
The default_authenticated Setting
The default_authenticated configuration option controls the starting state of every route’s authenticated annotation:
default_authenticated sets the baseline for all routes. Individual route blocks can override this via unauthenticated { ... } (to make specific routes public) or authenticate(...) (to set up the actual authentication mechanism).Authentication Providers
Torque Admin supports three providers, defined inMapper::Authentication::PROVIDERS:
| Provider | Block required? | How it works |
|---|---|---|
:rails | Yes | Your block is evaluated inside the standard ActionDispatch::Routing::Mapper, giving you access to the Rails authenticate constraint helper. |
:custom | Yes | Your block is evaluated inside the standard ActionDispatch::Routing::Mapper (via external), the same as :rails, so any standard Rails routing helpers are available. |
:devise | No | Automatically calls devise_for(resource, module: ...) via the external scope, wiring Devise’s session routes into the admin namespace. |
authenticate method is called inside your admin route definition:
external helper, which temporarily steps out of the admin mapper’s custom scope and into a plain ActionDispatch::Routing::Mapper — this is necessary so that helpers like devise_for or Rails’ authenticate constraint work correctly.
Devise Authentication
Devise is the most common Rails authentication library. Use the:devise provider — no block required — and Torque Admin will call devise_for with the correct namespace automatically:
authenticate_with_devise calls:
Admin::Devise::SessionsController), keeping them isolated from the main application’s Devise setup.
Rails Built-in Authentication (:rails)
Use :rails when you want to leverage Rails’ authenticate routing constraint. A block is required because Torque Admin cannot know in advance what constraint logic you need:
ActionDispatch::Routing::Mapper (via external), so all Rails routing helpers are available. The authenticate method inside the block is Rails’ own constraint — not Torque Admin’s.
Custom Authentication (:custom)
Use :custom when you have your own authentication library or a non-standard setup. A block is required, and it runs inside a standard ActionDispatch::Routing::Mapper (via external), giving you access to all standard Rails routing helpers:
Making Routes Public: unauthenticated
Even when default_authenticated is true, you can carve out individual route groups that should be publicly accessible using the unauthenticated helper. This sets authenticated: false on all routes inside the block:
Auth Annotations in Controllers
Every route processed by the admin engine carries anannotations hash that includes the authenticated flag. You can read this in controllers or middleware via route_annotation(:authenticated):
admin_application annotation is also available on every route, giving controllers a reference back to the Torque::Admin::Application instance that generated the route:
Registering Authenticable Resources
When you callauthenticate(resource, with: provider), Torque Admin internally calls authenticable_resource!(name, type) on the admin application to register the resource. This prevents the same resource from being registered twice:
ArgumentError is raised with a clear message. The registered resources are available via admin_application.auth_resources — a hash mapping resource name symbols to their provider type.
