api_register

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApiRegister

func ApiRegister(w http.ResponseWriter, r *http.Request, deps Dependencies)

ApiRegister is the HTTP-level helper that routes registration requests to either the passwordless or username+password flow based on the provided dependencies.

func ApiRegisterWithAuth

func ApiRegisterWithAuth(w http.ResponseWriter, r *http.Request, a types.AuthSharedInterface)

ApiRegisterWithAuth is a convenience wrapper that allows callers to pass a types.AuthSharedInterface (such as authImplementation) instead of manually wiring Dependencies. It constructs the Dependencies struct using the interface accessors and preserves the existing behaviour.

func RegisterPasswordlessInit

RegisterPasswordlessInit contains the core business logic of the passwordless registration init API. It validates input, generates the verification code, stores a temporary JSON payload and sends the email. It intentionally does not perform any logging; callers are responsible for mapping structured errors to their own logging and HTTP responses.

Types

type Dependencies

type Dependencies struct {
	// Passwordless indicates whether the registration flow is passwordless.
	Passwordless bool

	// RegisterPasswordlessInitDependencies are used when Passwordless is true.
	RegisterPasswordlessInitDependencies RegisterPasswordlessInitDependencies

	// RegisterWithUsernameAndPassword performs the username+password
	// registration when Passwordless is false. It is responsible for all
	// validation and business rules, and returns a user-facing success or
	// error message.
	RegisterWithUsernameAndPassword func(ctx context.Context, email, password, firstName, lastName, ip, userAgent string) (successMessage, errorMessage string)
}

Dependencies defines the dependencies required for handling the registration API endpoint. It combines both passwordless and username+password flows behind a shared interface.

type RegisterPasswordlessInitDependencies

type RegisterPasswordlessInitDependencies struct {
	DisableRateLimit bool

	TemporaryKeySet func(key string, value string, expiresSeconds int) error
	ExpiresSeconds  int

	EmailTemplate func(ctx context.Context, email string, verificationCode string) string
	EmailSend     func(ctx context.Context, email string, subject string, body string) error
}

RegisterPasswordlessInitDeps defines the dependencies required for the passwordless registration init (sending verification code).

type RegisterPasswordlessInitError

type RegisterPasswordlessInitError struct {
	Code    RegisterPasswordlessInitErrorCode
	Message string
	Err     error
}

RegisterPasswordlessInitError is a structured error for the registration init flow.

func (*RegisterPasswordlessInitError) Error

type RegisterPasswordlessInitErrorCode

type RegisterPasswordlessInitErrorCode string

RegisterPasswordlessInitErrorCode categorizes possible error sources.

const (
	RegisterPasswordlessInitErrorCodeNone           RegisterPasswordlessInitErrorCode = ""
	RegisterPasswordlessInitErrorCodeValidation     RegisterPasswordlessInitErrorCode = "validation"
	RegisterPasswordlessInitErrorCodeCodeGeneration RegisterPasswordlessInitErrorCode = "code_generation"
	RegisterPasswordlessInitErrorCodeSerialization  RegisterPasswordlessInitErrorCode = "serialization"
	RegisterPasswordlessInitErrorCodeTokenStore     RegisterPasswordlessInitErrorCode = "token_store"
	RegisterPasswordlessInitErrorCodeEmailSend      RegisterPasswordlessInitErrorCode = "email_send"
	RegisterPasswordlessInitErrorCodeInternal       RegisterPasswordlessInitErrorCode = "internal"
)

type RegisterPasswordlessInitResult

type RegisterPasswordlessInitResult struct {
	SuccessMessage string
}

RegisterPasswordlessInitResult represents a successful registration init.

Jump to

Keyboard shortcuts

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