bootstrap

package
v2.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bootstrap gates creation of the first user behind a one-time setup token.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// SetupToken is the operator-supplied token. When empty a random one is
	// generated at startup (if no user exists yet) and logged once.
	SetupToken string
	// OpenSignupAfterFirstUser reopens ordinary signup once the first user exists.
	OpenSignupAfterFirstUser bool
	// SuppressSetupTokenLog stops the generated token being logged; read it
	// with TheAuth.SetupToken instead.
	SuppressSetupTokenLog bool
	// OnFirstUser runs after the first user is created, for example to
	// grant the super admin role. Errors are logged and do not fail signup.
	OnFirstUser func(ctx context.Context, user *models.User) error
}

Config closes public signup and gates creation of the first user behind a one-time setup token (the storage must implement UserCountStorage). Password signup needs the token while no user exists. Magic-link signup cannot present a token, so the first admin signs up with a password. OnFirstUser grants the admin role.

type Gate

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

func New

func New(cfg *Config, counter UserCounter, limiter *throttle.Limiter) (*Gate, error)

func (*Gate) Begin

func (g *Gate) Begin(ctx context.Context) (func(*models.User), error)

Begin implements password.SignupGate and magiclink.SignupGate.

func (*Gate) Token

func (g *Gate) Token() string

Token returns the pending setup token, or "" once the first user exists.

type UserCounter

type UserCounter interface {
	CountUsers(ctx context.Context) (int, error)
}

UserCounter is the storage capability the gate needs.

Jump to

Keyboard shortcuts

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