user

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAPIKeyNotFound = errors.New("API key not found")
	ErrAPIKeyRevoked  = errors.New("API key has been revoked")
	ErrUserBanned     = errors.New("user account is banned")
	ErrUserNotFound   = errors.New("user not found")
)

Functions

This section is empty.

Types

type PostgresService

type PostgresService struct {
	// contains filtered or unexported fields
}

func NewPostgresService

func NewPostgresService(db pgc.Querier) *PostgresService

func (*PostgresService) GetOrCreateUser

func (s *PostgresService) GetOrCreateUser(ctx context.Context, whoopUserID int64) (string, bool, error)

func (*PostgresService) IsBanned

func (s *PostgresService) IsBanned(ctx context.Context, whoopUserID int64) (bool, error)

func (*PostgresService) UpdateAPIKeyLastUsed

func (s *PostgresService) UpdateAPIKeyLastUsed(ctx context.Context, apiKeyID int64) error

func (*PostgresService) ValidateAPIKey

func (s *PostgresService) ValidateAPIKey(ctx context.Context, apiKey string) (*ValidatedUser, error)

type Service

type Service interface {
	// ValidateAPIKey validates an API key and returns the associated user info.
	// Returns ErrAPIKeyNotFound if the key doesn't exist,
	// ErrAPIKeyRevoked if the key has been revoked,
	// or ErrUserBanned if the user account is banned.
	ValidateAPIKey(ctx context.Context, apiKey string) (*ValidatedUser, error)

	// GetOrCreateUser retrieves an existing user or creates a new one with an API key.
	// For new users, returns the plaintext API key (only time it's available).
	// For existing users, apiKey will be empty.
	GetOrCreateUser(ctx context.Context, whoopUserID int64) (apiKey string, banned bool, err error)

	// UpdateAPIKeyLastUsed updates the last_used_at timestamp for an API key.
	// This is typically called asynchronously after successful validation.
	UpdateAPIKeyLastUsed(ctx context.Context, apiKeyID int64) error

	// IsBanned checks if a user is banned.
	IsBanned(ctx context.Context, whoopUserID int64) (bool, error)
}

type ValidatedUser

type ValidatedUser struct {
	WhoopUserID int64
	APIKeyID    int64
}

Jump to

Keyboard shortcuts

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