supabase-community / gotrue-csharp

C# implementation of Supabase's GoTrue
https://supabase-community.github.io/gotrue-csharp/api/Supabase.Gotrue.Client.html
MIT License
39 stars 27 forks source link

StatelessClient SignIn "no Route matched with those values" #20

Closed fplaras closed 2 years ago

fplaras commented 2 years ago

Hi,

I was attempting to use the stateless client to signin a user but I keep getting the message "no Route matched with those values". Below is my client options configuration where I added both apikey header and Authorization in case it was an issue with headers. The key I am using is the anon key and the Url is the https://<project-ref>.supabase.co. I appreciate any help and guidance.

_clientOptions = clientOptions ?? new Gotrue.StatelessClient.StatelessClientOptions
            {
                Url = _config["Supabase:ApiUrl"],
                Headers = new Dictionary<string, string> { 
                    { "apikey", _config["Supabase:SystemApiKey"] },
                    { "Authorization", "Bearer " + _config["Supabase:SystemApiKey"] },
                    { "Content-Type", "application/json" },
                }
            };

var userSession = await Gotrue.StatelessClient.SignIn(signInModel.Email, signInModel.Password, _clientOptions);

I was following this example

# replace <project-ref> with your own project reference
# and SUPABASE_KEY with your anon api key
curl -X POST 'https://<project-ref>.supabase.co/auth/v1/magiclink' \
-H "apikey: SUPABASE_KEY" \
-H "Content-Type: application/json" \
fplaras commented 2 years ago

I just realized that the SignIn methods are missing the actual endpoint /auth and version. Wouldn't the endpoints be defined by the method being called and not established by the applications consuming the library? Maybe an Enum of endpoint routes and an enum or flag for the version?

acupofjose commented 2 years ago

@fplaras hope you had a happy New Year!

The gotrue-csharp library is meant to be server agnostic. From the stateless client, you'll have to use something to the equivalent of what is seen in the supabase-csharp repo (Supabase/Client.cs#L244).

public string AuthUrlFormat { get; set; } = "{0}/auth/v1";

So for your case, just switch out the URL parameter to something more like:

_clientOptions = clientOptions ?? new Gotrue.StatelessClient.StatelessClientOptions
{
    Url = "https://<project-ref>.supabase.co/auth/v1",
    // ... etc
};