auth

package
v0.33.12 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(next http.Handler) http.Handler

func AuthMiddlewareWithClient

func AuthMiddlewareWithClient(authClient AuthClient) func(http.Handler) http.Handler

func OptionalAuthMiddleware

func OptionalAuthMiddleware(next http.Handler) http.Handler

Validates JWT if present; doesn't require one.

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
}

type Config

type Config struct {
	AuthURL        string
	PublishableKey string
}

Config holds Supabase authentication configuration

func NewConfigFromEnv

func NewConfigFromEnv() (*Config, error)

NewConfigFromEnv creates auth config from environment variables

func (*Config) Validate

func (c *Config) Validate() error

Validate ensures all required configuration is present

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"`
}

func ValidateSession

func ValidateSession(tokenString string) *SessionInfo

type SupabaseAuthClient

type SupabaseAuthClient struct{}

func NewSupabaseAuthClient

func NewSupabaseAuthClient() *SupabaseAuthClient

func (*SupabaseAuthClient) ExtractTokenFromRequest

func (s *SupabaseAuthClient) ExtractTokenFromRequest(r *http.Request) (string, error)

func (*SupabaseAuthClient) SetUserInContext

func (s *SupabaseAuthClient) SetUserInContext(r *http.Request, user *UserClaims) *http.Request

func (*SupabaseAuthClient) ValidateToken

func (s *SupabaseAuthClient) ValidateToken(ctx context.Context, token string) (*UserClaims, error)

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"`
}

func GetUserFromContext

func GetUserFromContext(ctx context.Context) (*UserClaims, bool)

type UserContextKey

type UserContextKey string
const (
	UserKey UserContextKey = "user"
)

Jump to

Keyboard shortcuts

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