Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package supabase
import (
"errors"
"log"
"sync"
"time"

"github.com/supabase-community/functions-go"
Expand All @@ -14,7 +15,7 @@ import (

const (
REST_URL = "/rest/v1"
STORAGE_URL = "/storage/v1"
STORAGE_URL = "/storage/v1"
AUTH_URL = "/auth/v1"
FUNCTIONS_URL = "/functions/v1"
)
Expand All @@ -32,6 +33,7 @@ type Client struct {
type clientOptions struct {
url string
headers map[string]string
mutex *sync.Mutex
}

type ClientOptions struct {
Expand Down Expand Up @@ -62,6 +64,7 @@ func NewClient(url, key string, options *ClientOptions) (*Client, error) {

client := &Client{}
client.options.url = url
client.options.mutex = &sync.Mutex{}
// map is pass by reference, so this gets updated by rest of function
client.options.headers = headers

Expand Down Expand Up @@ -157,6 +160,9 @@ func (c *Client) RefreshToken(refreshToken string) (types.Session, error) {
}

func (c *Client) UpdateAuthSession(session types.Session) {
c.options.mutex.Lock()
defer c.options.mutex.Unlock()

c.Auth = c.Auth.WithToken(session.AccessToken)
c.rest.SetAuthToken(session.AccessToken)
c.options.headers["Authorization"] = "Bearer " + session.AccessToken
Expand Down