auth

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotAuthenticated is returned when a user is not authenticated
	ErrNotAuthenticated = fmt.Errorf("not authenticated")
	// ErrSessionExpired is returned when the session has expired
	ErrSessionExpired = fmt.Errorf("session expired")
)

Functions

func ClearSession

func ClearSession() error

ClearSession removes the current session

func GetAccessToken

func GetAccessToken() (string, error)

GetAccessToken returns the current access token if valid

func IsAuthenticated

func IsAuthenticated() bool

IsAuthenticated checks if there is a valid user session

func Logout

func Logout() error

Logout removes the current user session

func RequireAuth

func RequireAuth() error

RequireAuth returns an error if no user is authenticated

func SaveSession

func SaveSession(user *User) error

SaveSession saves a user session to disk

Types

type User

type User struct {
	ID           string    `json:"id"`
	Email        string    `json:"email"`
	Username     string    `json:"username,omitempty"`
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	ExpiresAt    time.Time `json:"expires_at"`
}

User represents an authenticated user

func FromSupabaseSession

func FromSupabaseSession(session *types.Session) *User

FromSupabaseSession creates a User from Supabase session

func GetCurrentUser

func GetCurrentUser() *User

GetCurrentUser returns the currently authenticated user, if any

func GetUserFromContext

func GetUserFromContext(ctx context.Context) *User

GetUserFromContext retrieves the user from a context

Jump to

Keyboard shortcuts

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