bootstrap

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 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.

While no user exists, password signup requires the token in the X-Setup-Token header or a "setupToken" body field. After the first user exists, signup is refused with CodeSignupClosed unless OpenSignupAfterFirstUser is set. Magic-link account creation follows the same rule but can never present a token, so the first admin must sign up with a password. Granting the new user an admin role is left to OnFirstUser.

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