responses

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package responses holds the request/response DTOs for the goravel-authkit HTTP endpoints. Swagger annotations on the controllers reference these types so the generated TypeScript SDK gets accurate models.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangePasswordRequest

type ChangePasswordRequest struct {
	CurrentPassword string `json:"currentPassword" binding:"required" example:"password"`
	NewPassword     string `json:"newPassword" binding:"required" example:"new-password"`
}

ChangePasswordRequest is the PUT /auth/password body.

type CreateUserRequest

type CreateUserRequest struct {
	Email    string `json:"email" binding:"required,email" example:"jane@example.com"`
	Name     string `json:"name" example:"Jane Admin"`
	Password string `json:"password" binding:"required" example:"password"`
	Role     string `json:"role" example:"admin"`
}

CreateUserRequest is the POST /users body.

type ErrorResponse

type ErrorResponse struct {
	Error   string `json:"error" example:"validation_error"`
	Message string `json:"message" example:"Email and password are required"`
}

ErrorResponse is the standard error envelope: {"error","message"}.

type LoginHistoryEntry

type LoginHistoryEntry struct {
	// Action is "auth.login" (password) or "auth.login_remember" (remember cookie).
	Action    string `json:"action" example:"auth.login"`
	IP        string `json:"ip" example:"203.0.113.7"`
	CreatedAt string `json:"createdAt" example:"2026-01-01T00:00:00Z"`
}

LoginHistoryEntry is one recent successful sign-in.

func NewLoginHistoryResponse

func NewLoginHistoryResponse(entries []models.AuditLog) []LoginHistoryEntry

NewLoginHistoryResponse maps audit rows to login-history DTOs.

type LoginRequest

type LoginRequest struct {
	Email    string `json:"email" form:"email" binding:"required,email" example:"admin@example.com"`
	Password string `json:"password" form:"password" binding:"required" example:"password"`
	// Remember, when true, issues a persistent "remember me" cookie so the user
	// stays logged in across browser restarts until it expires or they log out.
	Remember bool `json:"remember" form:"remember" example:"false"`
}

LoginRequest is the POST /auth/login body.

type MessageResponse

type MessageResponse struct {
	Message string `json:"message" example:"Password changed"`
}

MessageResponse is a simple {"message"} envelope.

type MetaFeatures

type MetaFeatures struct {
	UserManagement bool `json:"userManagement" example:"true"`
	TwoFactor      bool `json:"twoFactor" example:"true"`
	AuditLog       bool `json:"auditLog" example:"true"`
	Sessions       bool `json:"sessions" example:"true"`
}

MetaFeatures mirrors the authkit.features toggles for the frontend.

type MetaResponse

type MetaResponse struct {
	// Roles are the assignable role values (from authkit.roles). Empty = any.
	Roles             []string     `json:"roles"`
	MinPasswordLength int          `json:"minPasswordLength" example:"8"`
	Features          MetaFeatures `json:"features"`
}

MetaResponse exposes the FE-relevant, non-sensitive package config so the UI can adapt (role-select options, feature visibility, password rules) without hardcoding or duplicating it. Served unauthenticated at {prefix}/meta.

type RecoveryCodesResponse

type RecoveryCodesResponse struct {
	RecoveryCodes []string `json:"recoveryCodes" example:"ABCDE-FGHJK"`
}

RecoveryCodesResponse carries one-time recovery codes. Plaintext codes are shown exactly once, at confirmation / regeneration — they are stored hashed and can never be re-derived afterwards.

type RecoveryCodesStatusResponse

type RecoveryCodesStatusResponse struct {
	Remaining int `json:"remaining" example:"6"`
}

RecoveryCodesStatusResponse reports how many unused recovery codes remain, without revealing the codes themselves (they are stored hashed).

type SessionResponse

type SessionResponse struct {
	ID           string `json:"id" example:"3f2504e0-4f89-41d3-9a0c-0305e82c3301"`
	IP           string `json:"ip" example:"203.0.113.7"`
	UserAgent    string `json:"userAgent" example:"Mozilla/5.0 ..."`
	Current      bool   `json:"current" example:"true"`
	CreatedAt    string `json:"createdAt" example:"2026-01-01T00:00:00Z"`
	LastActiveAt string `json:"lastActiveAt" example:"2026-01-01T01:00:00Z"`
}

SessionResponse is the public view of one active session. The secret session id is never exposed; ID is the row's own id, used to address it for termination.

func NewSessionListResponse

func NewSessionListResponse(views []services.SessionView) []SessionResponse

NewSessionListResponse maps service session views to public DTOs.

type SetPasswordRequest

type SetPasswordRequest struct {
	Password string `json:"password" binding:"required" example:"new-password"`
}

SetPasswordRequest is the POST /users/{id}/password body.

type TwoFactorChallengeRequest

type TwoFactorChallengeRequest struct {
	Code         string `json:"code" example:"123456"`
	RecoveryCode string `json:"recoveryCode" example:"ABCDE-FGHJK"`
}

TwoFactorChallengeRequest completes a 2FA login with either a TOTP code or a recovery code (exactly one).

type TwoFactorConfirmRequest

type TwoFactorConfirmRequest struct {
	Code string `json:"code" binding:"required" example:"123456"`
}

TwoFactorConfirmRequest confirms enrollment with a TOTP code.

type TwoFactorDisableRequest

type TwoFactorDisableRequest struct {
	Password string `json:"password" binding:"required" example:"secret"`
}

TwoFactorDisableRequest re-authenticates with the account password before disabling 2FA.

type TwoFactorEnrollmentResponse

type TwoFactorEnrollmentResponse struct {
	Secret     string `json:"secret" example:"JBSWY3DPEHPK3PXP"`
	OtpauthURL string `json:"otpauthUrl" example:"otpauth://totp/App:admin@example.com?secret=...&issuer=App"`
}

TwoFactorEnrollmentResponse is returned when enrollment starts: the secret and the otpauth:// URL the client renders as a QR code.

type TwoFactorRequiredResponse

type TwoFactorRequiredResponse struct {
	TwoFactor bool `json:"two_factor" example:"true"`
}

TwoFactorRequiredResponse is returned by login when the user has 2FA enabled: the session is not established yet; the client must call the challenge endpoint.

type UpdateProfileRequest

type UpdateProfileRequest struct {
	Email string `json:"email" binding:"required,email" example:"admin@example.com"`
	Name  string `json:"name" example:"Admin"`
}

UpdateProfileRequest is the PUT /auth/me body — the user's own name and email.

type UpdateUserRequest

type UpdateUserRequest struct {
	Email    string `json:"email" binding:"required,email" example:"jane@example.com"`
	Name     string `json:"name" example:"Jane Admin"`
	Role     string `json:"role" example:"admin"`
	Disabled *bool  `json:"disabled" example:"false"`
}

UpdateUserRequest is the PUT /users/{id} body. Disabled is a pointer so an omitted field leaves the lock state unchanged.

type UserResponse

type UserResponse struct {
	ID               string `json:"id" example:"3f2504e0-4f89-41d3-9a0c-0305e82c3301"`
	Email            string `json:"email" example:"admin@example.com"`
	Name             string `json:"name" example:"Admin"`
	Role             string `json:"role" example:"admin"`
	TwoFactorEnabled bool   `json:"twoFactorEnabled" example:"false"`
	Disabled         bool   `json:"disabled" example:"false"`
	CreatedAt        string `json:"createdAt" example:"2026-01-01T00:00:00Z"`
}

UserResponse is the public view of a user (never includes the password hash).

func NewUserListResponse

func NewUserListResponse(users []models.User) []UserResponse

NewUserListResponse maps a slice of users to public DTOs.

func NewUserResponse

func NewUserResponse(u *models.User) UserResponse

NewUserResponse maps a User model to its public DTO.

Jump to

Keyboard shortcuts

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