basejump icon indicating copy to clipboard operation
basejump copied to clipboard

Confused on how to use RPC to get account info.

Open salvinoto opened this issue 11 months ago • 6 comments

Hi, so I am confused how to use the RPC methods to get the account info. What I'm trying to do is just have a single function to get the account for me, and it automatically determines whether the account selector is on a team or not. Currently is what I have below, and basically, it just checks to see if there is a slug in the URL. Basically im wondering if theres a better way to do this, because its very sloppy and its a huge mess. A huge issue too is that the RPCs dont get types when generated with the supabase CLI. Basically I'd like advice on how to implement this with it being disaster. Thanks.

EDIT: Even more so, it seems like Supabase is trying to find these RPC on the public schema, where they dont exist. Dont know how to fix that either or something like that Searched for the function public.get_account_by_slug without parameters or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache

`import { createClient } from "@/utils/supabase/server";

export interface AccountData { account_id: string; account_role: string; is_primary_owner: boolean; name: string; slug: string; personal_account: boolean; billing_enabled: boolean; billing_status: string; created_at: string; // Assuming timestamp is a string, adjust if it's a Date object updated_at: string; // Same assumption as created_at metadata: { [key: string]: any; // Adjust according to the known structure or keep it flexible }; }

export async function getAccountData({ params }: { params: { slug: string } }) { const supabase = createClient(); if (params.slug === "personal") { const { data, error } = await supabase.rpc("get_personal_account"); return { data: data as unknown as AccountData, error }; }

const { data, error } = await supabase.rpc("get_account_by_slug", { slug: params.slug, }); return { data: data as unknown as AccountData, error }; } `

salvinoto avatar Mar 14 '24 05:03 salvinoto