nedpals / supabase-go

Unofficial Supabase client library for Go.
https://pkg.go.dev/github.com/nedpals/supabase-go
MIT License
380 stars 73 forks source link

Auth.SignUp without password does not work #6

Closed princefishthrower closed 1 year ago

princefishthrower commented 1 year ago

As the title states, running some code like this:

s := supa.CreateClient(os.Getenv("SUPABASE_URL"), os.Getenv("SUPABASE_SERVICE_KEY"))
ctx := context.Background()
user, err := s.Auth.SignUp(ctx, supa.UserCredentials{
    Email: "someemail@gmail.com",
})
if err != nil {
    return err
}

Results in no user being created, and what's even more interesting is that err is not nil, but just an empty string! Would be intested in what is going wrong here, or perhaps what I am missing. (already doublechecked that the env vars are correct)

UPDATE: Okay, passing a random value for a password actually creates the user (note as per the docs the password is not required - referencing v1 docs here as I assume that is what this library is based off of). Then the next issue: the full user object isn't returned, I only get something like this:

{    0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC {} map[] 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC}
Fritte795 commented 1 year ago

The problem with an empty password might be that it does not match the desired length configured in your supabase instance. In my example a password too short would return Status 422 with the Information Password should be at least x characters.

In superbase.go line 86 in the function sendCustomRequest this response leads to Decoding the Body and writing it in a custom error struct. sendCustomRequest is called by sendRequest for the Sign-Up Process. Sign-In for example call directly sendCustomRequest. The problem is that the custom error in sendRequest is not passed by reference. Therefore it is always the empty default struct.

I could fix this bug for me by simply adding on char. I will prepare a pull request for this issue.

Fritte795 commented 1 year ago

Apparently it has already been fixed here: https://github.com/nedpals/supabase-go/commit/072657921ab1cffee2dbb90f70ea1afdbec07bfe

nedpals commented 1 year ago

I guess it's time to release a new version lol

Fritte795 commented 1 year ago

Perfect timing 😁 I suppose the returned user from signup is correct but it only contains default values for e.g. the last login time.

I think the issue can be closed @nedpals