Refactor database interface to use *sql.DB directly
Simplified the database layer by removing custom interface wrappers and using standard library *sql.DB and *sql.Tx types directly. Changes: - Removed DBConnection and DBTransaction interfaces from database.go - Removed NewDBConnection() wrapper function - Updated TokenGenerator to use *sql.DB instead of DBConnection - Updated all validation and revocation methods to accept *sql.Tx - Updated TableManager to work with *sql.DB directly - Updated all tests to use db.Begin() instead of custom wrappers - Fixed GeneratorConfig.DB field (was DBConn) - Updated documentation in doc.go with correct API usage Benefits: - Simpler API with fewer abstractions - Works directly with database/sql standard library - Compatible with GORM (via gormDB.DB()) and Bun (share same *sql.DB) - Easier to understand and maintain - No unnecessary wrapper layers Breaking changes: - GeneratorConfig.DBConn renamed to GeneratorConfig.DB - Removed NewDBConnection() function - pass *sql.DB directly - ValidateAccess/ValidateRefresh now accept *sql.Tx instead of DBTransaction - Token.Revoke/CheckNotRevoked now accept *sql.Tx instead of DBTransaction 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,21 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Generates an access token for the provided subject
|
||||
// NewAccess generates a new JWT access token for the specified subject (user).
|
||||
//
|
||||
// Parameters:
|
||||
// - subjectID: The user ID or subject identifier to associate with the token
|
||||
// - fresh: If true, marks the token as "fresh" for sensitive operations.
|
||||
// Fresh tokens are typically required for actions like changing passwords
|
||||
// or email addresses. The token remains fresh until FreshExpireAfter minutes.
|
||||
// - rememberMe: If true, the token is persistent (TTL="exp") and will be stored
|
||||
// with an expiration date. If false, it's session-only (TTL="session") and
|
||||
// expires when the browser closes.
|
||||
//
|
||||
// Returns:
|
||||
// - tokenString: The signed JWT token string
|
||||
// - expiresIn: Unix timestamp when the token expires
|
||||
// - err: Any error encountered during token generation
|
||||
func (gen *TokenGenerator) NewAccess(
|
||||
subjectID int,
|
||||
fresh bool,
|
||||
@@ -47,7 +61,19 @@ func (gen *TokenGenerator) NewAccess(
|
||||
return signedToken, expiresAt, nil
|
||||
}
|
||||
|
||||
// Generates a refresh token for the provided user
|
||||
// NewRefresh generates a new JWT refresh token for the specified subject (user).
|
||||
// Refresh tokens are used to obtain new access tokens without re-authentication.
|
||||
//
|
||||
// Parameters:
|
||||
// - subjectID: The user ID or subject identifier to associate with the token
|
||||
// - rememberMe: If true, the token is persistent (TTL="exp") and will be stored
|
||||
// with an expiration date. If false, it's session-only (TTL="session") and
|
||||
// expires when the browser closes.
|
||||
//
|
||||
// Returns:
|
||||
// - tokenStr: The signed JWT token string
|
||||
// - exp: Unix timestamp when the token expires
|
||||
// - err: Any error encountered during token generation
|
||||
func (gen *TokenGenerator) NewRefresh(
|
||||
subjectID int,
|
||||
rememberMe bool,
|
||||
|
||||
Reference in New Issue
Block a user