supabase-community / supabase-csharp

A C# Client library for Supabase
https://github.com/supabase-community/supabase-csharp/wiki
MIT License
481 stars 50 forks source link

Sign Up throws BadRequestException #166

Open MilesLitteral opened 1 month ago

MilesLitteral commented 1 month ago

Bug report

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

Note: Confirm you have new user sign up enabled

  1. Initialize Supabase and Auth client
  2. Call supabase.Auth.SignUp(<email>, <password>);
  3. Run
  4. See error BadRequestException:
{
    "component":"api",
    "error": "400: Could not parse request body as JSON:
        json: cannot unmarshal array into Go value of: 
        type struct {
            Email string \"json:\\\"email\\\"\"; 
            Phone string \"json:\\\"phone\\\"\" 
        }",
    "level":"info","method":"POST","msg":
        "400: Could not parse request body as JSON: 
        json: cannot unmarshal array into Go value of
        type struct { 
            Email string \"json:\\\"email\\\"\"; 
            Phone string \"json:\\\"phone\\\"\"
        }",
    "path":"/signup",
    "referer":"https://nltzzlfvjiejvzpuyigo.supabase.co/auth/v1/callback",
    "remote_addr":"98.116.40.56",
    "request_id":"8a74ad0f3776422f-EWR",
    "time":"2024-07-22T16:06:05Z"
}

Expected behavior

Sign Up user acknowledged in dashboard

System information

Additional context

Add any other context about the problem here.

MilesLitteral commented 1 month ago

I discovered that SignUp's var body = new Dictionary<string, object> { { "email", email }, { "password", password } }; is actually not writing to JSON correctly and is thus leading to error code 400 (malformed/bad request) responses. I wrote a new SignUp function using the UserAttributes class and will make a pull request as it does work correctly and creates users without error (ie: calling the function creates users on the Supabase dashboard and does serialize to json as the /signup endpoint desires.)

acupofjose commented 1 month ago

A PR is always welcome! Thanks @MilesLitteral

acupofjose commented 1 month ago

@MilesLitteral, I'm looking into your PR - I'm struggling to duplicate the malformed request issue you're seeing.

If it's a general issue, it should be present when testing in our CI against the latest released tag on the supabase/gotrue repo. I did update the repo because it was using an old tag for testing - but I'm not seeing any issue when testing against the SignUp method.

This makes me think it's a Unity issue - potentially a conflict between System.Text.Json and Newtonsoft.Json. Thoughts?

MilesLitteral commented 1 month ago

@MilesLitteral, I'm looking into your PR - I'm struggling to duplicate the malformed request issue you're seeing.

If it's a general issue, it should be present when testing in our CI against the latest released tag on the supabase/gotrue repo. I did update the repo because it was using an old tag for testing - but I'm not seeing any issue when testing against the SignUp method.

This makes me think it's a Unity issue - potentially a conflict between System.Text.Json and Newtonsoft.Json. Thoughts?

That's possible, I was under the impression it could be a general error because this issue came up when calling sign up regardless on my system though it could be a separate issue, however this function definitely works in Unity out of the box as the request isn't malformed when sending a UserAttributes object