types

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package types defines the domain models and request/response types used by the sms plugin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthResponse

type AuthResponse struct {
	User *auth.User `json:"user"`
}

AuthResponse is the data payload returned by SMS phone+password login and registration endpoints.

type LoginWithPhoneRequest

type LoginWithPhoneRequest struct {
	PhoneNumber string `json:"phoneNumber"` // Phone number in E.164 format
	Password    string `json:"password"`    // User password
}

LoginWithPhoneRequest represents phone+password login request.

Example:

{
  "phoneNumber": "+14155551234",
  "password": "SecurePassword123!"
}

type RegisterWithPhoneRequest

type RegisterWithPhoneRequest struct {
	Avatar      *string `json:"avatar"`      // Optional avatar URL
	Name        *string `json:"name"`        // User display name (required)
	PhoneNumber string  `json:"phoneNumber"` // Phone number in E.164 format (required)
	Password    string  `json:"password"`    // User password (required)
}

RegisterWithPhoneRequest represents phone+password registration request.

Example:

{
  "name": "John Doe",
  "phoneNumber": "+14155551234",
  "password": "SecurePassword123!",
  "avatar": "https://example.com/avatar.jpg"
}

type SendOTPRequest

type SendOTPRequest struct {
	PhoneNumber string `json:"phoneNumber"` // Phone number to send OTP to
	UserID      string `json:"userId"`      // User ID requesting OTP
	Purpose     string `json:"purpose"`     // OTP purpose ("phone_verification", "password_reset", "login_mfa")
}

SendOTPRequest represents the request to send an OTP code.

Example:

{
  "phoneNumber": "+14155551234",
  "userId": "user_123",
  "purpose": "phone_verification"
}

type Store

type Store interface {

	// CreateUser creates a new user with a phone number.
	//
	// The phone is initially unverified (phoneVerified: false).
	//
	// Parameters:
	//   - ctx: Request context
	//   - user: User with phone field populated in E.164 format
	//
	// Returns:
	//   - *User: Created user
	//   - error: If user creation fails (e.g., duplicate phone)
	CreateUser(ctx context.Context, user User) (*User, error)

	// GetUserByID retrieves a user by their ID.
	//
	// Used for:
	//   - Enriching user data with phone verification status
	//   - Looking up phone data by user ID
	//
	// Parameters:
	//   - ctx: Request context
	//   - id: User ID to lookup
	//
	// Returns:
	//   - *User: User with matching ID
	//   - error: If user not found or database error
	GetUserByID(ctx context.Context, id string) (*User, error)

	// GetUserByPhone retrieves a user by phone number.
	//
	// Used for:
	//   - Phone+password login
	//   - Checking if phone already exists during registration
	//   - Phone verification lookup
	//
	// Parameters:
	//   - ctx: Request context
	//   - phone: Phone number to lookup (E.164 format)
	//
	// Returns:
	//   - *User: User with matching phone
	//   - error: If user not found or database error
	GetUserByPhone(ctx context.Context, phone string) (*User, error)

	// UpdateUserPhone updates a user's phone number and verification status.
	//
	// Used after successful OTP verification to mark phone as verified.
	//
	// Parameters:
	//   - ctx: Request context
	//   - userID: User ID
	//   - phone: New phone number (E.164 format)
	//   - verified: Phone verification status
	//
	// Returns:
	//   - error: If update fails
	UpdateUserPhone(ctx context.Context, userID, phone string, verified bool) error
}

Store defines the interface for SMS OTP verification storage operations.

This interface provides phone-specific user management operations:

  • User creation with phone numbers
  • Phone lookup for authentication
  • Phone verification status updates

Thread Safety: Implementations must be safe for concurrent use.

type User

type User struct {
	auth.User
	Phone         *string `json:"phone,omitempty"` // User phone number in E.164 format
	PhoneVerified bool    `json:"phoneVerified"`   // Phone verification status
}

User extends the core User model with phone-specific fields.

This model adds phone verification status for display in API responses.

Use this when:

  • Returning user data after phone registration
  • Displaying phone verification status in user profiles
  • Checking if user has verified their phone

Example:

user := types.User{
  User: auth.User{ID: "user_123", Name: "John Doe"},
  Phone: ptr("+14155551234"),
  PhoneVerified: true,
}

type VerifyOTPRequest

type VerifyOTPRequest struct {
	PhoneNumber string `json:"phoneNumber"` // Phone number to verify
	Code        string `json:"code"`        // OTP code to verify
	Purpose     string `json:"purpose"`     // OTP purpose
}

VerifyOTPRequest represents the request to verify an OTP code.

Example:

{
  "phoneNumber": "+14155551234",
  "code": "123456",
  "purpose": "phone_verification"
}

Jump to

Keyboard shortcuts

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