Documentation
¶
Index ¶
- func AuthMiddleware() router.Middleware
- func GetUserID(ctx *nhttp.Context) string
- func HealthHandler() func(w http.ResponseWriter, r *http.Request)
- func OptionalAuthMiddleware() router.Middleware
- func SetGlobal(c *Client)
- type AdminUpdateUserRequest
- type AdminUserListResponse
- type AuthClient
- func (a *AuthClient) AdminDeleteUser(userID string) error
- func (a *AuthClient) AdminGetUser(userID string) (*AuthUser, error)
- func (a *AuthClient) AdminListUsers(page, perPage int) ([]AuthUser, error)
- func (a *AuthClient) AdminUpdateUser(userID string, req AdminUpdateUserRequest) (*AuthUser, error)
- func (a *AuthClient) GenerateLink(linkType, email string, options map[string]any) (map[string]any, error)
- func (a *AuthClient) GetUser(accessToken string) (*AuthUser, error)
- func (a *AuthClient) InviteByEmail(req InviteRequest) (*AuthUser, error)
- func (a *AuthClient) RefreshToken(refreshToken string) (*AuthSession, error)
- func (a *AuthClient) ResetPasswordForEmail(email string) error
- func (a *AuthClient) SignInWithOTP(req OTPRequest) error
- func (a *AuthClient) SignInWithPassword(req SignInRequest) (*AuthSession, error)
- func (a *AuthClient) SignOut(accessToken string) error
- func (a *AuthClient) SignUp(req SignUpRequest) (*AuthSession, error)
- func (a *AuthClient) UpdateUser(accessToken string, req UpdateUserRequest) (*AuthUser, error)
- type AuthSession
- type AuthUser
- type BroadcastHandler
- type BroadcastPayload
- type Bucket
- type BucketHandle
- func (b *BucketHandle) Copy(from, to string) error
- func (b *BucketHandle) CreateSignedURL(path string, expiresIn time.Duration) (string, error)
- func (b *BucketHandle) Download(path string) (io.ReadCloser, error)
- func (b *BucketHandle) GetDownloadURL(path string) string
- func (b *BucketHandle) GetPublicURL(path string) string
- func (b *BucketHandle) GetTransformURL(path string, opts TransformOptions) string
- func (b *BucketHandle) List(prefix string, opts ...ListOption) ([]StorageObject, error)
- func (b *BucketHandle) Move(from, to string) error
- func (b *BucketHandle) Remove(paths []string) error
- func (b *BucketHandle) Update(path string, body io.Reader, contentType ...string) error
- func (b *BucketHandle) Upload(path string, body io.Reader, contentType ...string) error
- type ChangeHandler
- type ChangePayload
- type Channel
- func (ch *Channel) Broadcast(event string, payload map[string]any) error
- func (ch *Channel) OnBroadcast(event string, handler BroadcastHandler) *Channel
- func (ch *Channel) OnPostgresChanges(event RealtimeEvent, handler ChangeHandler) *Channel
- func (ch *Channel) OnPresence(handler PresenceHandler) *Channel
- func (ch *Channel) Subscribe() error
- func (ch *Channel) Track(state map[string]any) error
- func (ch *Channel) Unsubscribe() error
- type Client
- type ColumnInfo
- type Config
- type FunctionResponse
- type FunctionsClient
- type InviteRequest
- type InvokeOptions
- type JWTClaims
- type ListOption
- type OTPRequest
- type Plugin
- type PresenceHandler
- type PresencePayload
- type RealtimeClient
- type RealtimeEvent
- type RefreshTokenRequest
- type ResetPasswordRequest
- type ResizeMode
- type SignInRequest
- type SignUpRequest
- type SignedURLResult
- type StorageClient
- type StorageObject
- type TransformOptions
- type UpdateUserRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware() router.Middleware
AuthMiddleware returns a Nimbus middleware that validates the Supabase JWT from the Authorization header and sets the claims on the context.
Register it globally or per-route:
app.Router.Use(supabase.AuthMiddleware())
Or via named middleware:
protected := app.Router.Group("/api", supabase.AuthMiddleware())
func GetUserID ¶
GetUserID is a convenience to extract the user ID from the context. Returns empty string if unauthenticated.
func HealthHandler ¶
func HealthHandler() func(w http.ResponseWriter, r *http.Request)
HealthHandler returns an HTTP handler that reports Supabase health. Mount it manually if you want a dedicated endpoint:
app.Router.Get("/supabase/health", supabase.HealthHandler())
func OptionalAuthMiddleware ¶
func OptionalAuthMiddleware() router.Middleware
OptionalAuthMiddleware is like AuthMiddleware but does not reject unauthenticated requests — it just sets claims if a valid token is present.
Types ¶
type AdminUpdateUserRequest ¶
type AdminUpdateUserRequest struct {
Email string `json:"email,omitempty"`
Password string `json:"password,omitempty"`
Phone string `json:"phone,omitempty"`
UserMetadata map[string]any `json:"user_metadata,omitempty"`
AppMetadata map[string]any `json:"app_metadata,omitempty"`
BanDuration string `json:"ban_duration,omitempty"`
}
AdminUpdateUserRequest is the payload for admin user update.
type AdminUserListResponse ¶
type AdminUserListResponse struct {
Users []AuthUser `json:"users"`
}
AdminUserListResponse is the response from admin list users.
type AuthClient ¶
type AuthClient struct {
// contains filtered or unexported fields
}
AuthClient wraps the Supabase GoTrue API.
func (*AuthClient) AdminDeleteUser ¶
func (a *AuthClient) AdminDeleteUser(userID string) error
AdminDeleteUser deletes a user by ID (requires service role key).
func (*AuthClient) AdminGetUser ¶
func (a *AuthClient) AdminGetUser(userID string) (*AuthUser, error)
AdminGetUser retrieves a user by ID (requires service role key).
func (*AuthClient) AdminListUsers ¶
func (a *AuthClient) AdminListUsers(page, perPage int) ([]AuthUser, error)
AdminListUsers lists all users (requires service role key).
func (*AuthClient) AdminUpdateUser ¶
func (a *AuthClient) AdminUpdateUser(userID string, req AdminUpdateUserRequest) (*AuthUser, error)
AdminUpdateUser updates a user by ID (requires service role key).
func (*AuthClient) GenerateLink ¶
func (a *AuthClient) GenerateLink(linkType, email string, options map[string]any) (map[string]any, error)
GenerateLink creates an admin action link (confirm, recovery, etc.).
func (*AuthClient) GetUser ¶
func (a *AuthClient) GetUser(accessToken string) (*AuthUser, error)
GetUser retrieves the user associated with the given access token.
func (*AuthClient) InviteByEmail ¶
func (a *AuthClient) InviteByEmail(req InviteRequest) (*AuthUser, error)
InviteByEmail sends an invitation email (requires service role key).
func (*AuthClient) RefreshToken ¶
func (a *AuthClient) RefreshToken(refreshToken string) (*AuthSession, error)
RefreshToken exchanges a refresh token for new access/refresh tokens.
func (*AuthClient) ResetPasswordForEmail ¶
func (a *AuthClient) ResetPasswordForEmail(email string) error
ResetPasswordForEmail sends a password reset email.
func (*AuthClient) SignInWithOTP ¶
func (a *AuthClient) SignInWithOTP(req OTPRequest) error
SignInWithOTP sends a magic link or OTP to the user.
func (*AuthClient) SignInWithPassword ¶
func (a *AuthClient) SignInWithPassword(req SignInRequest) (*AuthSession, error)
SignInWithPassword authenticates with email and password.
session, err := client.Auth.SignInWithPassword(supabase.SignInRequest{
Email: "user@example.com", Password: "secret123",
})
func (*AuthClient) SignOut ¶
func (a *AuthClient) SignOut(accessToken string) error
SignOut invalidates the user's session.
func (*AuthClient) SignUp ¶
func (a *AuthClient) SignUp(req SignUpRequest) (*AuthSession, error)
SignUp registers a new user with email and password.
session, err := client.Auth.SignUp(supabase.SignUpRequest{
Email: "user@example.com", Password: "secret123",
})
func (*AuthClient) UpdateUser ¶
func (a *AuthClient) UpdateUser(accessToken string, req UpdateUserRequest) (*AuthUser, error)
UpdateUser updates the currently authenticated user.
type AuthSession ¶
type AuthSession struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
ExpiresAt int64 `json:"expires_at,omitempty"`
RefreshToken string `json:"refresh_token"`
User AuthUser `json:"user"`
}
AuthSession contains tokens returned after authentication.
type AuthUser ¶
type AuthUser struct {
ID string `json:"id"`
Email string `json:"email"`
Phone string `json:"phone,omitempty"`
Role string `json:"role,omitempty"`
EmailConfirmedAt string `json:"email_confirmed_at,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
AppMetadata map[string]any `json:"app_metadata,omitempty"`
UserMetadata map[string]any `json:"user_metadata,omitempty"`
}
AuthUser represents a Supabase user.
type BroadcastHandler ¶
type BroadcastHandler func(payload BroadcastPayload)
BroadcastHandler is called on broadcast messages.
type BroadcastPayload ¶
type BroadcastPayload struct {
Event string `json:"event"`
Payload map[string]any `json:"payload"`
}
BroadcastPayload is delivered for broadcast events.
type Bucket ¶
type Bucket struct {
ID string `json:"id"`
Name string `json:"name"`
Public bool `json:"public"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
Bucket represents a Supabase Storage bucket.
type BucketHandle ¶
type BucketHandle struct {
// contains filtered or unexported fields
}
BucketHandle provides operations on a specific storage bucket.
func (*BucketHandle) Copy ¶
func (b *BucketHandle) Copy(from, to string) error
Copy copies a file within the bucket.
func (*BucketHandle) CreateSignedURL ¶
CreateSignedURL returns a time-limited signed URL for private access.
func (*BucketHandle) Download ¶
func (b *BucketHandle) Download(path string) (io.ReadCloser, error)
Download returns a reader for the file. Caller must close the returned ReadCloser.
func (*BucketHandle) GetDownloadURL ¶
func (b *BucketHandle) GetDownloadURL(path string) string
GetDownloadURL returns a public download URL with download disposition.
func (*BucketHandle) GetPublicURL ¶
func (b *BucketHandle) GetPublicURL(path string) string
GetPublicURL returns the public URL for a file (bucket must be public).
func (*BucketHandle) GetTransformURL ¶
func (b *BucketHandle) GetTransformURL(path string, opts TransformOptions) string
GetTransformURL returns a URL for image transformations (Supabase Image Transformation).
func (*BucketHandle) List ¶
func (b *BucketHandle) List(prefix string, opts ...ListOption) ([]StorageObject, error)
List returns objects in the bucket under the given prefix.
func (*BucketHandle) Move ¶
func (b *BucketHandle) Move(from, to string) error
Move renames/moves a file within the bucket.
func (*BucketHandle) Remove ¶
func (b *BucketHandle) Remove(paths []string) error
Remove deletes one or more files from the bucket.
type ChangeHandler ¶
type ChangeHandler func(payload ChangePayload)
ChangeHandler is called when a Postgres change event matches.
type ChangePayload ¶
type ChangePayload struct {
Schema string `json:"schema"`
Table string `json:"table"`
Type RealtimeEvent `json:"type"`
Record map[string]any `json:"record"`
OldRecord map[string]any `json:"old_record"`
Columns []ColumnInfo `json:"columns"`
}
ChangePayload is delivered to listeners on Postgres change events.
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel represents a subscription to a Supabase Realtime channel.
func (*Channel) OnBroadcast ¶
func (ch *Channel) OnBroadcast(event string, handler BroadcastHandler) *Channel
OnBroadcast registers a handler for broadcast events.
func (*Channel) OnPostgresChanges ¶
func (ch *Channel) OnPostgresChanges(event RealtimeEvent, handler ChangeHandler) *Channel
OnPostgresChanges registers a handler for Postgres change events.
func (*Channel) OnPresence ¶
func (ch *Channel) OnPresence(handler PresenceHandler) *Channel
OnPresence registers a handler for presence events.
func (*Channel) Unsubscribe ¶
Unsubscribe leaves the channel.
type Client ¶
type Client struct {
// Sub-clients for each Supabase service.
Storage *StorageClient
Functions *FunctionsClient
Realtime *RealtimeClient
Auth *AuthClient
// contains filtered or unexported fields
}
Client is the core Supabase client that all sub-clients use.
type ColumnInfo ¶
ColumnInfo describes a single column in a change payload.
type Config ¶
type Config struct {
// URL is the Supabase project URL (e.g. https://xyz.supabase.co).
URL string
// AnonKey is the public API key for client-side access.
AnonKey string
// ServiceRoleKey is the server-side key with full access (bypasses RLS).
ServiceRoleKey string
// JWTSecret is the JWT secret for verifying Supabase access tokens.
// Found in Supabase Dashboard → Settings → API → JWT Secret.
JWTSecret string
// DatabaseURL is the direct Postgres connection string for lucid/GORM.
// If set, the plugin auto-configures the database connection.
DatabaseURL string
// DatabaseDebug enables SQL logging.
DatabaseDebug bool
// DatabasePool configures connection pooling.
DatabasePool database.PoolConfig
}
Config holds Supabase plugin configuration.
func ConfigFromEnv ¶
func ConfigFromEnv() Config
ConfigFromEnv builds config from environment variables.
type FunctionResponse ¶
type FunctionResponse struct {
StatusCode int
Headers http.Header
// contains filtered or unexported fields
}
FunctionResponse is the result of invoking an Edge Function.
func (*FunctionResponse) Body ¶
func (r *FunctionResponse) Body() []byte
Body returns the raw response body.
func (*FunctionResponse) JSON ¶
func (r *FunctionResponse) JSON(v any) error
JSON decodes the response body into v.
func (*FunctionResponse) Text ¶
func (r *FunctionResponse) Text() string
Text returns the response body as a string.
type FunctionsClient ¶
type FunctionsClient struct {
// contains filtered or unexported fields
}
FunctionsClient invokes Supabase Edge Functions.
func (*FunctionsClient) Invoke ¶
func (f *FunctionsClient) Invoke(name string, payload any, opts ...InvokeOptions) (*FunctionResponse, error)
Invoke calls a Supabase Edge Function by name with a JSON payload.
resp, err := client.Functions.Invoke("hello", map[string]any{"name": "World"})
var result map[string]string
resp.JSON(&result)
func (*FunctionsClient) InvokeRaw ¶
func (f *FunctionsClient) InvokeRaw(name string, body io.Reader, contentType string) (*FunctionResponse, error)
InvokeRaw calls an Edge Function with a raw body (non-JSON).
type InviteRequest ¶
type InviteRequest struct {
Email string `json:"email"`
Data map[string]any `json:"data,omitempty"`
}
InviteRequest is the payload for admin user invitation.
type InvokeOptions ¶
InvokeOptions configures an Edge Function invocation.
type JWTClaims ¶
type JWTClaims struct {
Sub string `json:"sub"`
Email string `json:"email"`
Phone string `json:"phone,omitempty"`
Role string `json:"role"`
Aud string `json:"aud"`
Exp int64 `json:"exp"`
Iat int64 `json:"iat"`
Iss string `json:"iss"`
AppMetadata map[string]any `json:"app_metadata,omitempty"`
UserMetadata map[string]any `json:"user_metadata,omitempty"`
}
JWTClaims contains decoded Supabase JWT claims.
func GetClaims ¶
GetClaims extracts the Supabase JWT claims from the request context. Returns nil if the middleware has not set claims (unauthenticated).
func MyHandler(ctx *http.Context) error {
claims := supabase.GetClaims(ctx)
if claims == nil {
return ctx.JSON(401, map[string]string{"error": "unauthorized"})
}
fmt.Println("User:", claims.UserID())
}
type ListOption ¶
type ListOption func(*listOpts)
func WithLimit ¶
func WithLimit(n int) ListOption
func WithOffset ¶
func WithOffset(n int) ListOption
type OTPRequest ¶
type OTPRequest struct {
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
}
OTPRequest is the payload for magic link / OTP sign-in.
type Plugin ¶
type Plugin struct {
nimbus.BasePlugin
// contains filtered or unexported fields
}
Plugin integrates Supabase services (DB, Auth, Storage, Edge Functions, Realtime, PostgREST) into Nimbus.
func (*Plugin) HealthChecks ¶
HealthChecks reports Supabase connectivity status.
func (*Plugin) Middleware ¶
func (p *Plugin) Middleware() map[string]router.Middleware
Middleware exposes named middleware for route assignment.
protected := app.Router.Group("/api", app.Middleware("supabase.auth"))
type PresenceHandler ¶
type PresenceHandler func(payload PresencePayload)
PresenceHandler is called on presence sync/join/leave.
type PresencePayload ¶
type PresencePayload struct {
Key string `json:"key"`
NewState map[string]any `json:"new_state"`
OldState map[string]any `json:"old_state"`
}
PresencePayload represents a presence state change.
type RealtimeClient ¶
type RealtimeClient struct {
// OnError is called when a connection or reconnection error occurs.
// Set this before calling Connect to observe errors.
OnError func(err error)
// contains filtered or unexported fields
}
RealtimeClient manages WebSocket channels to Supabase Realtime.
func (*RealtimeClient) Channel ¶
func (r *RealtimeClient) Channel(topic string) *Channel
Channel returns (or creates) a channel for the given topic.
func (*RealtimeClient) Close ¶
func (r *RealtimeClient) Close()
Close shuts down the realtime connection. Safe to call multiple times.
func (*RealtimeClient) Connect ¶
func (r *RealtimeClient) Connect() error
Connect establishes the WebSocket connection to Supabase Realtime.
type RealtimeEvent ¶
type RealtimeEvent string
RealtimeEvent is the type of database change event.
const ( EventInsert RealtimeEvent = "INSERT" EventUpdate RealtimeEvent = "UPDATE" EventDelete RealtimeEvent = "DELETE" EventAll RealtimeEvent = "*" )
type RefreshTokenRequest ¶
type RefreshTokenRequest struct {
RefreshToken string `json:"refresh_token"`
}
RefreshTokenRequest is the payload for refreshing tokens.
type ResetPasswordRequest ¶
type ResetPasswordRequest struct {
Email string `json:"email"`
}
ResetPasswordRequest is the payload for password reset.
type ResizeMode ¶
type ResizeMode string
const ( ResizeCover ResizeMode = "cover" ResizeContain ResizeMode = "contain" ResizeFill ResizeMode = "fill" )
type SignInRequest ¶
SignInRequest is the payload for email/password sign-in.
type SignUpRequest ¶
type SignUpRequest struct {
Email string `json:"email"`
Password string `json:"password"`
Data map[string]any `json:"data,omitempty"`
}
SignUpRequest is the payload for email/password sign-up.
type SignedURLResult ¶
type SignedURLResult struct {
SignedURL string `json:"signedURL"`
}
SignedURLResult is the response from createSignedUrl.
type StorageClient ¶
type StorageClient struct {
// contains filtered or unexported fields
}
StorageClient provides access to Supabase Storage buckets and objects.
func (*StorageClient) CreateBucket ¶
func (s *StorageClient) CreateBucket(name string, public bool) error
CreateBucket creates a new storage bucket.
func (*StorageClient) DeleteBucket ¶
func (s *StorageClient) DeleteBucket(name string) error
DeleteBucket deletes an empty bucket.
func (*StorageClient) From ¶
func (s *StorageClient) From(bucket string) *BucketHandle
From returns a handle to the named bucket.
client.Storage.From("avatars").Upload("user1.png", file)
func (*StorageClient) ListBuckets ¶
func (s *StorageClient) ListBuckets() ([]Bucket, error)
ListBuckets returns all storage buckets.
type StorageObject ¶
type StorageObject struct {
Name string `json:"name"`
ID string `json:"id,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
StorageObject represents a file in a bucket.
type TransformOptions ¶
type TransformOptions struct {
Width int
Height int
Quality int
Format string
Resize ResizeMode
}
TransformOptions for Supabase image transformations.