supabase

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: MIT Imports: 10 Imported by: 0

README

An isomorphic Go client for Supabase.

Features

  • Integration with Supabase.Realtime
    • Realtime listeners for database changes
  • Integration with Postgrest
    • Access your database using a REST API generated from your schema & database functions
  • Integration with Gotrue
    • User authentication, including OAuth, email/password, and native sign-in
  • Integration with Supabase Storage
    • Store files in S3 with additional managed metadata
  • Integration with Supabase Edge Functions
    • Run serverless functions on the edge

Quickstart

  1. To get started, create a new project in the Supabase Admin Panel.
  2. Grab your Supabase URL and Supabase Public Key from the Admin Panel (Settings -> API Keys).
  3. Initialize the client!

Reminder: supabase-go has some APIs that require the service_key rather than the public_key (for instance: the administration of users, bypassing database roles, etc.). If you are using the service_key be sure it is not exposed client side. Additionally, if you need to use both a service account and a public/user account, please do so using a separate client instance for each.

Documentation

Get Started

First of all, you need to install the library:

  go get github.com/supabase-community/supabase-go

Then you can use

  client, err := supabase.NewClient(API_URL, API_KEY, &supabase.ClientOptions{})
  if err != nil {
    fmt.Println("cannot initalize client", err)
  }
  data, count, err := client.From("countries").Select("*", "exact", false).Execute()

Use authenticated client


 client, err := supabase.NewClient(API_URL, API_KEY, &supabase.ClientOptions{})
 if err != nil {
  fmt.Println("cannot initalize client", err)
 }
 client.SignInWithEmailPassword(USER_EMAIL, USER_PASSWORD)

Documentation

Index

Constants

View Source
const (
	REST_URL      = "/rest/v1"
	STORAGE_URL   = "/storage/v1"
	AUTH_URL      = "/auth/v1"
	FUNCTIONS_URL = "/functions/v1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Storage *storage_go.Client
	// Auth is an interface. We don't need a pointer to an interface.
	Auth      auth.Client
	Functions *functions.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(url, key string, options *ClientOptions) (*Client, error)

func (*Client) AdminCreateUser added in v0.2.0

func (*Client) AdminDeleteUser added in v0.2.0

func (c *Client) AdminDeleteUser(userID string) error

func (*Client) AdminGetUser added in v0.2.0

func (c *Client) AdminGetUser(userID string) (*types.AdminGetUserResponse, error)

func (*Client) AdminListUsers added in v0.2.0

func (c *Client) AdminListUsers() (*types.AdminListUsersResponse, error)

func (*Client) AdminUpdateUser added in v0.2.0

func (c *Client) AdminUpdateUser(userID string, updates types.AdminUpdateUserRequest) (*types.AdminUpdateUserResponse, error)

func (*Client) EnableTokenAutoRefresh

func (c *Client) EnableTokenAutoRefresh(session types.Session)

---------------------------- Session Management ---------------------------- //

func (*Client) ExchangeCode

func (c *Client) ExchangeCode(code, codeVerifier string) (types.Session, error)

func (*Client) From

func (c *Client) From(table string) *postgrest.QueryBuilder

func (*Client) GetUser added in v0.2.0

func (c *Client) GetUser() (*types.UserResponse, error)

---------------------------- User Functions ---------------------------- //

func (*Client) HealthCheck added in v0.2.0

func (c *Client) HealthCheck() (*types.HealthCheckResponse, error)

func (*Client) Logout added in v0.2.0

func (c *Client) Logout() error

func (*Client) RefreshToken

func (c *Client) RefreshToken(refreshToken string) (types.Session, error)

func (*Client) Rpc

func (c *Client) Rpc(name, count string, rpcBody interface{}) string

func (*Client) SignInWithEmailPassword

func (c *Client) SignInWithEmailPassword(email, password string) (types.Session, error)

func (*Client) SignInWithPhonePassword

func (c *Client) SignInWithPhonePassword(phone, password string) (types.Session, error)

func (*Client) SignInWithProvider

func (c *Client) SignInWithProvider(provider types.Provider, redirectTo string) (*types.AuthorizeResponse, error)

func (*Client) SignUp

func (c *Client) SignUp(email, password string, data map[string]interface{}) (*types.SignupResponse, error)

---------------------------- Auth Functions ---------------------------- //

func (*Client) SignUpWithEmailOTP

func (c *Client) SignUpWithEmailOTP(email string, options *SignUpOptions) error

func (*Client) UpdateAuthSession

func (c *Client) UpdateAuthSession(session types.Session)

func (*Client) UpdatePassword added in v0.2.0

func (c *Client) UpdatePassword(newPassword string) error

func (*Client) UpdateUser added in v0.2.0

func (c *Client) UpdateUser(updates types.UpdateUserRequest) (*types.UpdateUserResponse, error)

func (*Client) VerifyEmailOTP

func (c *Client) VerifyEmailOTP(email, code string) (*types.Session, error)

type ClientOptions

type ClientOptions struct {
	Headers map[string]string
	Schema  string
}

type SignUpOptions

type SignUpOptions struct {
	Data       map[string]interface{}
	RedirectTo string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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