Refactored several Supabase client functions and updated them to use generics. Also, the '@kit/supabase-config' package was removed from the project and all references were replaced accordingly. The project's dependencies were updated as well, including the Supabase package which was upgraded to the latest version.
38 lines
858 B
TypeScript
38 lines
858 B
TypeScript
import { cache } from 'react';
|
|
|
|
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
|
|
|
import { Database } from '~/lib/database.types';
|
|
|
|
export const loadUserWorkspace = cache(async () => {
|
|
const client = getSupabaseServerComponentClient();
|
|
|
|
const accounts = await loadUserAccounts(client);
|
|
const { data } = await client.auth.getSession();
|
|
|
|
return {
|
|
accounts,
|
|
session: data.session,
|
|
};
|
|
});
|
|
|
|
async function loadUserAccounts(
|
|
client: ReturnType<typeof getSupabaseServerComponentClient<Database>>,
|
|
) {
|
|
const { data: accounts, error } = await client
|
|
.from('user_accounts')
|
|
.select(`name, slug, picture_url`);
|
|
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
|
|
return accounts.map(({ name, slug, picture_url }) => {
|
|
return {
|
|
label: name,
|
|
value: slug,
|
|
image: picture_url,
|
|
};
|
|
});
|
|
}
|