Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide examples for authentication etc. #20

Closed
Carnageous opened this issue Nov 21, 2021 · 7 comments
Closed

Provide examples for authentication etc. #20

Carnageous opened this issue Nov 21, 2021 · 7 comments

Comments

@Carnageous
Copy link
Contributor

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.

  • (How) should I use the client.TokenAuth method?
  • Can I encode the credentials into the HTTP URI somehow?

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
Copy link
Member

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

@Carnageous
Copy link
Contributor Author

Carnageous commented Nov 21, 2021

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
Copy link
Contributor Author

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?

  • I got an error from Supabase/Kong: No API key found in request
    • Was able to fix this by adding an apikey header to the request, next to the Authorization one. (It is stated in the supabase docs, that this is required)
  • One of the headers in client.go caused an issue. Removing the extra : solved it. I opened a PR for both fixes.

@muratmirgun
Copy link
Member

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
Copy link
Member

I'm looking at the pr you sent

@CMiksche
Copy link

CMiksche commented Sep 4, 2022

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants