feat: implement loadCurrentUserAccounts for user account management in SiteLayout

This commit is contained in:
Danel Kungla
2025-07-24 16:13:32 +03:00
parent a85f26d55b
commit 87363051cd
2 changed files with 35 additions and 13 deletions

View File

@@ -0,0 +1,31 @@
import { cache } from 'react';
import { requireUserInServerComponent } from '@/lib/server/require-user-in-server-component';
import { createAccountsApi } from '@kit/accounts/api';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
export type Accounts = Awaited<ReturnType<typeof loadAccounts>>;
/**
* @name loadUserAccount
* @description
* Load the user account. It's a cached per-request function that fetches the user workspace data.
* It can be used across the server components to load the user workspace data.
*/
export const loadAccounts = cache(accountsLoader);
export async function loadCurrentUserAccounts() {
const client = getSupabaseServerClient();
const {
data: { user },
} = await client.auth.getUser();
return user?.identities?.[0]?.id ? await loadAccounts() : [];
}
async function accountsLoader() {
const client = getSupabaseServerClient();
const api = createAccountsApi(client);
return api.loadUserAccounts();
}