Files
medreport_mrb2b/app/home/(user)/_lib/server/load-accounts.ts
Helena 9122acc89f MED-151: add profile view and working smoking dashboard card (#71)
* MED-151: add profile view and working smoking dashboard card

* update zod

* move some components to shared

* move some components to shared

* remove console.logs

* remove unused password form components

* only check null for variant

* use pathsconfig
2025-09-04 12:17:54 +03:00

31 lines
887 B
TypeScript

import { cache } from 'react';
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();
}