Documentation
¶
Index ¶
- func ApiRegister(w http.ResponseWriter, r *http.Request, deps Dependencies)
- func ApiRegisterWithAuth(w http.ResponseWriter, r *http.Request, a types.AuthSharedInterface)
- func RegisterPasswordlessInit(ctx context.Context, r *http.Request, ...) (*RegisterPasswordlessInitResult, *RegisterPasswordlessInitError)
- type Dependencies
- type RegisterPasswordlessInitDependencies
- type RegisterPasswordlessInitError
- type RegisterPasswordlessInitErrorCode
- type RegisterPasswordlessInitResult
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 ¶
func RegisterPasswordlessInit(ctx context.Context, r *http.Request, deps RegisterPasswordlessInitDependencies) (*RegisterPasswordlessInitResult, *RegisterPasswordlessInitError)
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)
// Logger is used to log internal errors. If nil, slog.Default() is used.
Logger *slog.Logger
}
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 ¶
func (e *RegisterPasswordlessInitError) Error() string
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.