accessadmin

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package accessadmin decides plugin/admin's permissions with plugin/access roles: better-auth's admin `ac` and `roles` options. It is the adapter that lets the admin plugin, which lives in the core module and imports no permission engine, use fine-grained roles from the access module:

authz := accessadmin.MustNew(accessadmin.DefaultAccessControl, map[string]access.Role{"support": support})
auth.New(db, auth.WithPlugins(admin.New(admin.WithAuthorizer(authz), …)))

Without it the admin plugin keeps its two built-in roles (admin, user).

Index

Constants

This section is empty.

Variables

View Source
var DefaultAccessControl = access.MustNew(access.Statements(admin.DefaultStatements.Clone()))

DefaultAccessControl is the access control of admin.DefaultStatements, the vocabulary every admin operation asks from. An app adding resources of its own builds one from a copy of admin.DefaultStatements.

View Source
var ErrNoAccessControl = errors.New("accessadmin: needs an access control")

ErrNoAccessControl is New with a nil access control.

Functions

func DefaultRoles

func DefaultRoles() map[string]access.Role

DefaultRoles returns admin.DefaultRoles as access roles of DefaultAccessControl; a new map each call.

Types

type Authorizer

type Authorizer struct {
	// contains filtered or unexported fields
}

Authorizer is an admin.Authorizer and admin.RoleCatalog over access roles. Build it with New; it is immutable afterwards and safe for concurrent use.

func MustNew

func MustNew(ac *access.AccessControl, roles map[string]access.Role) *Authorizer

MustNew is New for roles known at compile time; it panics on an error, which then shows at start-up.

func New

func New(ac *access.AccessControl, roles map[string]access.Role) (*Authorizer, error)

New builds the authorizer from ac and roles, which are added to DefaultRoles or replace one of them under its name. Every role must name only statements ac declares, and every name must be one name without commas, as admin_role stores several comma-joined.

func (*Authorizer) Authorize

func (a *Authorizer) Authorize(_ context.Context, req admin.AccessRequest) (bool, error)

Authorize allows req when one of its roles passes the whole request under its connector, as better-auth checks a user with several roles. It never fails.

func (*Authorizer) DefinesRole

func (a *Authorizer) DefinesRole(name string) bool

DefinesRole reports whether name is one of the authorizer's roles, which set-role then accepts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL