Admin

Manage users and sessions as an administrator.

This page documents the current Ruby port behavior. Ruby uses snake_case option names and auth.api method names; HTTP paths and JSON keys keep the upstream wire shape where implemented.

Configure

config/auth.rb
require "better_auth"

auth = BetterAuth.auth(
  secret: ENV.fetch("BETTER_AUTH_SECRET"),
  base_url: ENV.fetch("BETTER_AUTH_URL", "http://localhost:3000"),
  plugins: [
    BetterAuth::Plugins.admin(admin_roles: ["admin"], default_role: "user")
  ]
)

Usage

server.rb
users = auth.api.list_users(headers: { "cookie" => admin_cookie }, query: { searchValue: "ada", searchField: "email" })
auth.api.set_role(headers: { "cookie" => admin_cookie }, body: { userId: users[:users].first["id"], role: "admin" })

Routes

MethodPathRuby API method
GET/admin/list-usersauth.api.list_users
POST/admin/create-userauth.api.create_user
POST/admin/set-roleauth.api.set_role
POST/admin/ban-userauth.api.ban_user
POST/admin/unban-userauth.api.unban_user
POST/admin/impersonate-userauth.api.impersonate_user
POST/admin/set-user-passwordauth.api.set_user_password
POST/admin/has-permissionauth.api.user_has_permission

Options

Current Ruby options accepted by BetterAuth::Plugins.admin:

  • default_role
  • admin_roles
  • banned_user_message
  • impersonation_session_duration
  • ac
  • roles
  • default_ban_expires_in
  • default_ban_reason
  • allow_impersonating_admins
  • admin_user_ids

Support Notes

  • The examples above are based on Ruby plugin source and tests in packages/better_auth.
  • If an upstream section is not represented here, treat it as not yet documented or not yet supported by the Ruby port until the matching Ruby implementation exists.

On this page