feat(account): add team membership check and refactor user account loading in HomeLayout

This commit is contained in:
Danel Kungla
2025-08-21 21:32:17 +03:00
parent cdf1491e53
commit 492327c5c7
2 changed files with 51 additions and 3 deletions

View File

@@ -0,0 +1,34 @@
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 UserAccount = Awaited<
ReturnType<typeof hasAccountTeamMembershipLoader>
>;
/**
* @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 loadHasTeamMembership = cache(hasAccountTeamMembershipLoader);
export async function loadHasAccountTeamMembership() {
const user = await requireUserInServerComponent();
return user?.identities?.[0]?.id
? await loadHasTeamMembership(user?.identities?.[0]?.id)
: null;
}
async function hasAccountTeamMembershipLoader(
accountId: string,
): Promise<boolean> {
const client = getSupabaseServerClient();
const api = createAccountsApi(client);
return api.hasAccountTeamMembership(accountId);
}