summaryrefslogtreecommitdiff
path: root/types/types.go
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2026-04-22 04:46:24 +0900
committerhaturatu <taro@eyes4you.org>2026-04-22 04:46:24 +0900
commit4b0271272e983fdb85d4b816cbd91f34d91a7884 (patch)
treead92ba661f0f9e8b16d93f333ebf43ffd331a892 /types/types.go
parentd18b4f9d615d8942ff604a53be92da2c8e853635 (diff)
feat(backend): pocketbase authHEADmain
Diffstat (limited to 'types/types.go')
-rw-r--r--types/types.go63
1 files changed, 23 insertions, 40 deletions
diff --git a/types/types.go b/types/types.go
index 44cb60a..a975f0e 100644
--- a/types/types.go
+++ b/types/types.go
@@ -1,14 +1,11 @@
package types
import (
- "database/sql"
"sync"
"time"
)
-// PathConfig holds the configurable paths for the application routes and assets.
type PathConfig struct {
- // Paths
Login string
Register string
Logout string
@@ -20,68 +17,56 @@ type PathConfig struct {
FrontPath string
APIPath string
- // Booleans
ProtectFrontend bool
ProtectAPI bool
RegisterEnabled bool
- // Security Policies
- MaxLoginAttempts int
- LockoutDurationMinutes int
- RateLimitMaxRequests int
- RateLimitWindowSeconds int
- PasswordPolicy string
-
- // Token Durations
- TokenDurationHours int
+ MaxLoginAttempts int
+ LockoutDurationMinutes int
+ RateLimitMaxRequests int
+ RateLimitWindowSeconds int
+ PasswordPolicy string
+ TokenDurationHours int
AccessTokenDurationMinutes int
- RefreshTokenDurationDays int
+ RefreshTokenDurationDays int
}
-// ContextKey is a custom type for context keys to avoid collisions.
type ContextKey string
-// SessionDataContextKey is the key for storing session data in the request context.
const SessionDataContextKey = ContextKey("sessionData")
-// User represents a user in the database
type User struct {
- ID int64 `json:"id"`
- Username string `json:"username"`
- PasswordHash string `json:"-"`
- Role string `json:"role"`
- IsActive bool `json:"is_active"`
- FailedLogins int `json:"failed_logins"`
- LastLoginAt sql.NullTime `json:"last_login_at"`
- CreatedAt time.Time `json:"created_at"`
- UpdatedAt time.Time `json:"updated_at"`
+ ID string `json:"id"`
+ Username string `json:"username"`
+ Role string `json:"role"`
+ IsActive bool `json:"is_active"`
+ FailedLogins int `json:"failed_logins"`
+ LastLoginAt *time.Time `json:"last_login_at"`
+ CreatedAt time.Time `json:"created_at"`
+ UpdatedAt time.Time `json:"updated_at"`
}
-// AuthToken represents a token in the database
type AuthToken struct {
- ID int64
- UserID int64
+ UserID string
Token string
ExpiresAt time.Time
}
-// RefreshToken represents a refresh token in the database
type RefreshToken struct {
- ID int64
- UserID int64
+ UserID string
Token string
ExpiresAt time.Time
IsRevoked bool
}
-// JWTPayload defines the claims for the access token.
type JWTPayload struct {
- UserID int64 `json:"user_id"`
- Role string `json:"role"`
- Exp int64 `json:"exp"`
+ UserID string `json:"user_id"`
+ Username string `json:"username"`
+ Role string `json:"role"`
+ TokenType string `json:"token_type"`
+ Exp int64 `json:"exp"`
}
-// RateLimiter represents a user-specific rate limiter.
type RateLimiter struct {
Requests map[string][]int64
Mutex sync.Mutex
@@ -89,7 +74,6 @@ type RateLimiter struct {
Window time.Duration
}
-// WorkerPool manages a pool of goroutines to execute tasks concurrently.
type WorkerPool struct {
Workers int
TaskQueue chan func()
@@ -98,8 +82,7 @@ type WorkerPool struct {
Active int64
}
-// EnrichedUser is a wrapper for User with additional computed fields for admin views.
type EnrichedUser struct {
*User
TimeSinceLogin string `json:"time_since_login"`
-} \ No newline at end of file
+}