supabase-community / postgrest-go

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

RPC no Route matched #30

Closed irohitb closed 1 year ago

irohitb commented 1 year ago

Bug report

Describe the bug

setup_workspace type generated on client looks like this

   setup_workspace: {
        Args: {
          refresh_token: string
          user_email: string
          name: string
          is_admin: string
          workspace_name: string
        }

In go, when I am calling it


        supabaseReqData := supabase.SetupWorkspaceRequest{
            Name:    userData.Name,
            UserEmail:   userData.Email,
            RefreshToken: request.RefreshToken,
            IsAdmin: userData.IsAdmin,
            WorkspaceName: userData.Hd,
        }
        payload, err := json.Marshal(supabaseReqData)
        if err != nil {
            fmt.Println("Error encoding JSON:", err)
            return
        }

        result := db.Rpc("setup_workspace", "", string(payload))

it is throwing the following error: "message":"No API key found in request"

Here supabase.SetupWorkspaceRequest

type SetupWorkspaceRequest struct {
    RefreshToken  string `json:"refresh_token"`
    UserEmail     string `json:"user_email"`
    Name          string `json:"name"`
    IsAdmin       bool   `json:"is_admin"`
    WorkspaceName string `json:"workspace_name"`
}

And db is db *postgrest.Client

I am initializing like this

    supbaseDb := postgrest.NewClient(url,serviceRoleKey, nil)
    if supbaseDb.ClientError != nil {
        panic(supbaseDb.ClientError)
    }
    app.Db = supbaseDb

where url is this http://localhost:54321 and serviceRoleKey is what we get when we do supabase start (service_role key)

In NodeJs, this code would've like this

    supbaseDb := postgrest.NewClient(url+"/rest/v1", "", map[string]string{
        "service_role_key": serviceRoleKey,
    })
irohitb commented 1 year ago

Changing it to this fixed it

    supbaseDb := postgrest.NewClient(url+"/rest/v1", "", map[string]string{
        "Authorization": "Bearer " + serviceRoleKey,
        "apikey": serviceRoleKey,
    })