supabase-community / postgrest-go

Isomorphic Go client for PostgREST. (Now Updating)
https://supabase.io
Apache License 2.0
170 stars 27 forks source link

Provide examples for authentication etc. #20

Closed Carnageous closed 2 years ago

Carnageous commented 2 years ago

Hey! I love the idea behind this package, but have some troubles with getting started, as I am new to Supabase and PostgREST.

I would love to see some more examples on the usage of this package (with supabase), namely authentication.

For anything I tried, I get some not-so-descriptive error (like just EOF from net/url) which is very likely because I did something wrong.

All the examples I can find are just for a local setup without auth. Maybe adding a few more tests would be ideal for this? I would love to contribute once I used this a bit more.

I would greatly appreciate any help :)

muratmirgun commented 2 years ago

If it's okay, could you post the code snippet of the part where you got the error? Or the error itself?

Carnageous commented 2 years ago

Yeah sure, thanks!

At first I tried something like this:

connUrl := "http://" + user + ":" + password + "@" + host + ":" + port + "/" + dbName

client := postgrest.NewClient(connUrl, "public", nil)
res, err := client.From("my_table").Select("*", "", false).Execute()

if err != nil {
    // I get an error from net/url: "invalid port \":myPassword after host"
    panic(err)
}

fmt.Println(res)

But having the credentials in the URL did not seem to work (even when I did connUrl = url.QueryEscape(connUrl) I got an error).

Then I tried to use the TokenAuth method like this:

client := postgrest.NewClient(connUrl, "public", nil)

client.TokenAuth("mySupabaseKey")

res, err := client.From("my_table").Select("*", "", false).Execute()

if err != nil {
    // I get a net/url Error: "EOF"
    panic(err)
}

using the API key I got from the supabase settings.

Does this look somewhat right to you

// Edit I did find out in the meantime, that I have to use the /rest/v1 path for the connection string. Now I get something that looks like a connection timeout/error. Sorry for making this sound like a stack overflow page, I just wanted to ask for examples :D

Carnageous commented 2 years ago

Alright, so I was able to fix my problems! One of them was simply me doing mistakes (this is why I would love better docs), but I think I found two bugs as well?

muratmirgun commented 2 years ago

Yes, there is some deficiency in the document part, I will complete those parts as soon as possible, I am also looking at the errors you sent. Thanks

muratmirgun commented 2 years ago

I'm looking at the pr you sent

CMiksche commented 2 years ago

@muratmirgun There is still no example for the Auth on the README or at pkg.go.dev

I am thinking about using Supabase for multiple projects, but I have to integrate it with my own backend, so a documentation how to connect with Authentication would be really nice for people like me.

YancyFrySr commented 1 year ago

would also very much appreciate an auth example if this is possible