Documentation
¶
Index ¶
- func ApiAuthenticateViaUsername(w http.ResponseWriter, r *http.Request, username, firstName, lastName string, ...)
- func ApiAuthenticateViaUsernameWithAuth(w http.ResponseWriter, r *http.Request, username, firstName, lastName string, ...)
- func AuthenticateViaUsername(ctx context.Context, username, firstName, lastName string, deps Dependencies) (*AuthenticateResult, *AuthenticateError)
- type AuthenticateError
- type AuthenticateErrorCode
- type AuthenticateResult
- type Dependencies
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApiAuthenticateViaUsername ¶
func ApiAuthenticateViaUsername(w http.ResponseWriter, r *http.Request, username, firstName, lastName string, deps Dependencies)
ApiAuthenticateViaUsername is the HTTP-level helper that wires request/response handling to the core AuthenticateViaUsername business logic using the provided dependencies.
func ApiAuthenticateViaUsernameWithAuth ¶
func ApiAuthenticateViaUsernameWithAuth(w http.ResponseWriter, r *http.Request, username, firstName, lastName string, a types.AuthSharedInterface)
ApiAuthenticateViaUsernameWithAuth 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 AuthenticateViaUsername ¶
func AuthenticateViaUsername(ctx context.Context, username, firstName, lastName string, deps Dependencies) (*AuthenticateResult, *AuthenticateError)
AuthenticateViaUsername contains the core business logic for authenticating a user given a username (or email) and optional first/last name. It does not log or write HTTP responses.
Types ¶
type AuthenticateError ¶
type AuthenticateError struct {
Code AuthenticateErrorCode
Message string
Err error
}
AuthenticateError represents a structured error in the authentication flow.
func (*AuthenticateError) Error ¶
func (e *AuthenticateError) Error() string
type AuthenticateErrorCode ¶
type AuthenticateErrorCode string
AuthenticateErrorCode categorizes error sources in the authentication flow.
const ( AuthenticateErrorCodeNone AuthenticateErrorCode = "" AuthenticateErrorCodeUserLookup AuthenticateErrorCode = "user_lookup" AuthenticateErrorCodeCodeGen AuthenticateErrorCode = "code_generation" AuthenticateErrorCodeTokenStore AuthenticateErrorCode = "token_store" )
type AuthenticateResult ¶
type AuthenticateResult struct {
Token string
}
AuthenticateResult represents a successful authentication.
type Dependencies ¶
type Dependencies struct {
Passwordless bool
PasswordlessUserFindByEmail func(ctx context.Context, email string) (string, error)
UserFindByUsername func(ctx context.Context, username, firstName, lastName string) (string, error)
UserStoreAuthToken func(ctx context.Context, token, userID string) error
UseCookies bool
SetAuthCookie func(w http.ResponseWriter, r *http.Request, token string)
// Logger is used to log internal errors. If nil, slog.Default() is used.
Logger *slog.Logger
}
Dependencies defines the dependencies required for authenticating a user by username (or email) and returning an auth token.