Skip to content

Commit 9f6d333

Browse files
Merge pull request #31 from radeqq007/main
docs: improve documentation
2 parents f46491f + 1daf511 commit 9f6d333

File tree

1 file changed

+82
-12
lines changed

1 file changed

+82
-12
lines changed

README.md

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ An isomorphic Go client for Supabase.
77
- [x] Integration with [Postgrest](https://github.com/supabase-community/postgrest-go)
88
- Access your database using a REST API generated from your schema & database functions
99
- [x] Integration with [Gotrue](https://github.com/supabase-community/gotrue-go)
10-
- User authentication, including OAuth, ***email/password***, and native sign-in
10+
- User authentication, including OAuth, **_email/password_**, and native sign-in
1111
- [x] Integration with [Supabase Storage](https://github.com/supabase-community/storage-go)
1212
- Store files in S3 with additional managed metadata
1313
- [x] Integration with [Supabase Edge Functions](https://github.com/supabase-community/functions-go)
@@ -19,36 +19,106 @@ An isomorphic Go client for Supabase.
1919
2. Grab your Supabase URL and Supabase Public Key from the Admin Panel (Settings -> API Keys).
2020
3. Initialize the client!
2121

22-
*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.*
22+
_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._
2323

2424
## Documentation
2525

26-
### Get Started
26+
### Installation
2727

28-
First of all, you need to install the library:
28+
Install the library to your go project:
2929

3030
```sh
3131
go get github.com/supabase-community/supabase-go
3232
```
3333

34-
Then you can use
34+
### Quick start
3535

3636
```go
3737
client, err := supabase.NewClient(API_URL, API_KEY, &supabase.ClientOptions{})
3838
if err != nil {
39-
fmt.Println("cannot initalize client", err)
39+
fmt.Println("Failed to initalize the client: ", err)
4040
}
41+
```
42+
43+
### Client configuration
44+
45+
#### Basic Client
46+
47+
```go
48+
client, err := supabase.NewClient(url, key, nil)
49+
```
50+
51+
#### Client with custom options
52+
53+
```go
54+
options := &supabase.ClientOptions{
55+
Headers: map[string]string{
56+
"X-Custom-Header": "custom-value",
57+
},
58+
Schema: "custom_schema", // defaults to "public"
59+
}
60+
61+
client, err := supabase.NewClient(url, key, options)
62+
```
63+
64+
### Querying data
65+
66+
```go
67+
// ...
68+
4169
data, count, err := client.From("countries").Select("*", "exact", false).Execute()
4270
```
4371

44-
### Use authenticated client
72+
For more see [postgrest-go Query Builder documentation](https://pkg.go.dev/github.com/supabase-community/postgrest-go#QueryBuilder)
73+
74+
### Authentication
75+
76+
The client provides comprehensive authentication features through the integrated GoTrue client.
77+
78+
#### Email/Password Authentication
79+
80+
```go
81+
// Sign in with email and password
82+
session, err := client.SignInWithEmailPassword("[email protected]", "password")
83+
if err != nil {
84+
log.Fatal("Sign in failed:", err)
85+
}
86+
87+
fmt.Printf("User ID: %s\n", session.User.ID)
88+
fmt.Printf("Access Token: %s\n", session.AccessToken)
89+
90+
```
91+
92+
#### Phone/Password Authentication
4593

4694
```go
95+
// Sign in with phone and password
96+
session, err := client.SignInWithPhonePassword("+1234567890", "password")
97+
if err != nil {
98+
log.Fatal("Sign in failed:", err)
99+
}
100+
```
101+
102+
### Token Management
103+
104+
#### Manual Token Refresh
105+
106+
```go
107+
// Refresh an expired token
108+
newSession, err := client.RefreshToken(session.RefreshToken)
109+
if err != nil {
110+
log.Fatal("Token refresh failed:", err)
111+
}
112+
```
47113

48-
client, err := supabase.NewClient(API_URL, API_KEY, &supabase.ClientOptions{})
49-
if err != nil {
50-
fmt.Println("cannot initalize client", err)
51-
}
52-
client.SignInWithEmailPassword(USER_EMAIL, USER_PASSWORD)
114+
#### Automatic Token Refresh
115+
116+
```go
117+
// Enable automatic token refresh in the background
118+
client.EnableTokenAutoRefresh(session)
53119

120+
// The client will automatically:
121+
// - Refresh tokens before they expire (at 75% of expiry time)
122+
// - Retry failed refreshes with exponential backoff
123+
// - Update all service clients with new tokens
54124
```

0 commit comments

Comments
 (0)