Documentation
¶
Index ¶
- func AuthMiddleware(next http.Handler) http.Handler
- func AuthMiddlewareWithClient(authClient AuthClient) func(http.Handler) http.Handler
- func OptionalAuthMiddleware(next http.Handler) http.Handler
- type AuthClient
- type Config
- type SessionInfo
- type SupabaseAuthClient
- type UserClaims
- type UserContextKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
AuthMiddleware validates Supabase JWT tokens (uses default SupabaseAuthClient)
func AuthMiddlewareWithClient ¶
func AuthMiddlewareWithClient(authClient AuthClient) func(http.Handler) http.Handler
AuthMiddlewareWithClient validates JWT tokens using the provided AuthClient
Types ¶
type AuthClient ¶
type AuthClient interface {
ValidateToken(ctx context.Context, token string) (*UserClaims, error)
ExtractTokenFromRequest(r *http.Request) (string, error)
SetUserInContext(r *http.Request, user *UserClaims) *http.Request
}
AuthClient defines the interface for authentication operations
type Config ¶
Config holds Supabase authentication configuration
func NewConfigFromEnv ¶
NewConfigFromEnv creates auth config from environment variables
type SessionInfo ¶
type SessionInfo struct {
IsValid bool `json:"is_valid"`
ExpiresAt int64 `json:"expires_at,omitempty"`
RefreshNeeded bool `json:"refresh_needed"`
UserID string `json:"user_id,omitempty"`
Email string `json:"email,omitempty"`
}
SessionInfo holds session information and token validity
func ValidateSession ¶
func ValidateSession(tokenString string) *SessionInfo
ValidateSession validates a JWT token and returns session information
type SupabaseAuthClient ¶
type SupabaseAuthClient struct{}
SupabaseAuthClient implements AuthClient for Supabase authentication
func NewSupabaseAuthClient ¶
func NewSupabaseAuthClient() *SupabaseAuthClient
NewSupabaseAuthClient creates a new SupabaseAuthClient
func (*SupabaseAuthClient) ExtractTokenFromRequest ¶
func (s *SupabaseAuthClient) ExtractTokenFromRequest(r *http.Request) (string, error)
ExtractTokenFromRequest extracts a JWT token from the Authorization header
func (*SupabaseAuthClient) SetUserInContext ¶
func (s *SupabaseAuthClient) SetUserInContext(r *http.Request, user *UserClaims) *http.Request
SetUserInContext adds user claims to the request context
func (*SupabaseAuthClient) ValidateToken ¶
func (s *SupabaseAuthClient) ValidateToken(ctx context.Context, token string) (*UserClaims, error)
ValidateToken validates a Supabase JWT token
type UserClaims ¶
type UserClaims struct {
jwt.RegisteredClaims
UserID string `json:"sub"`
Email string `json:"email"`
AppMetadata map[string]any `json:"app_metadata"`
UserMetadata map[string]any `json:"user_metadata"`
Role string `json:"role"`
}
UserClaims represents the Supabase JWT claims
func GetUserFromContext ¶
func GetUserFromContext(ctx context.Context) (*UserClaims, bool)
GetUserFromContext extracts user claims from the request context
type UserContextKey ¶
type UserContextKey string
UserContextKey is the key used to store user claims in the request context
const (
UserKey UserContextKey = "user"
)