Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetUserIDOrZero ¶
GetUserIDOrZero retrieves user ID from context, returns zero value if not found Used for optional auth scenarios on public endpoints.
func MustGetUserID ¶
MustGetUserID retrieves the authenticated user ID from context For protected endpoints, user_id must exist, otherwise panic This is the recommended approach since auth interceptor guarantees user_id existence
Types ¶
type AuthInterceptor ¶
type AuthInterceptor struct {
// contains filtered or unexported fields
}
AuthInterceptor provides JWT authentication for Connect RPC endpoints
func NewAuthInterceptor ¶
func NewAuthInterceptor(validator *JWTValidator, publicProcedures []string) *AuthInterceptor
NewAuthInterceptor creates a new auth interceptor publicProcedures should contain procedure names that don't require authentication
type Claims ¶
type Claims struct {
Sub string `json:"sub"` // User ID (UUID format from Supabase)
Email string `json:"email"` // Optional email
jwt.RegisteredClaims
}
Claims represents the JWT claims from Supabase auth tokens
type JWTValidator ¶
type JWTValidator struct {
// contains filtered or unexported fields
}
JWTValidator validates JWT tokens using JWKS from Supabase
func NewJWTValidator ¶
func NewJWTValidator(ctx context.Context, cfg *JWTValidatorConfig) (*JWTValidator, error)
NewJWTValidator creates a new JWT validator with JWKS auto-refresh
func (*JWTValidator) Close ¶
func (v *JWTValidator) Close() error
Close stops the JWKS background refresh and cleans up resources
func (*JWTValidator) ValidateToken ¶
ValidateToken validates a JWT token and returns the claims
type JWTValidatorConfig ¶
type JWTValidatorConfig struct {
JWKSURL string // JWKS endpoint URL
RefreshPeriod time.Duration // How often to refresh JWKS (default: 1 hour)
}
JWTValidatorConfig holds configuration for JWT validation