From c238e08fa700e465693e0cec10193710ac00a6b0 Mon Sep 17 00:00:00 2001 From: giancarlo Date: Tue, 16 Apr 2024 22:41:06 +0800 Subject: [PATCH] Replace session with user in team accounts This commit replaces the session object with the user object in the team accounts feature. This change is reflected in the team-account-danger-zone, layout, team-account-workspace, and billing components. The usage of the user object provides more specificity and accuracy in handling user information compared to the more generic session object. --- .../[account]/_lib/server/team-account-workspace.loader.ts | 6 +++--- apps/web/app/(dashboard)/home/[account]/billing/page.tsx | 1 + apps/web/app/(dashboard)/home/[account]/layout.tsx | 2 +- .../src/components/settings/team-account-danger-zone.tsx | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/web/app/(dashboard)/home/[account]/_lib/server/team-account-workspace.loader.ts b/apps/web/app/(dashboard)/home/[account]/_lib/server/team-account-workspace.loader.ts index cca38ac87..03977bcc0 100644 --- a/apps/web/app/(dashboard)/home/[account]/_lib/server/team-account-workspace.loader.ts +++ b/apps/web/app/(dashboard)/home/[account]/_lib/server/team-account-workspace.loader.ts @@ -30,12 +30,12 @@ export const loadTeamWorkspace = cache(async (accountSlug: string) => { accountResult, accountsResult, { - data: { session }, + data: { user }, }, ] = await Promise.all([ accountPromise, accountsPromise, - client.auth.getSession(), + client.auth.getUser(), ]); if (accountResult.error) { @@ -63,6 +63,6 @@ export const loadTeamWorkspace = cache(async (accountSlug: string) => { return { account: accountData, accounts: accountsResult.data, - session, + user, }; }); diff --git a/apps/web/app/(dashboard)/home/[account]/billing/page.tsx b/apps/web/app/(dashboard)/home/[account]/billing/page.tsx index 6562ee9c7..325d07ad6 100644 --- a/apps/web/app/(dashboard)/home/[account]/billing/page.tsx +++ b/apps/web/app/(dashboard)/home/[account]/billing/page.tsx @@ -37,6 +37,7 @@ export const generateMetadata = async () => { async function TeamAccountBillingPage({ params }: Params) { const workspace = await loadTeamWorkspace(params.account); const accountId = workspace.account.id; + const [subscription, customerId] = await loadTeamAccountBillingPage(accountId); diff --git a/apps/web/app/(dashboard)/home/[account]/layout.tsx b/apps/web/app/(dashboard)/home/[account]/layout.tsx index 9ee09e07c..5cf0438ec 100644 --- a/apps/web/app/(dashboard)/home/[account]/layout.tsx +++ b/apps/web/app/(dashboard)/home/[account]/layout.tsx @@ -32,7 +32,7 @@ function TeamWorkspaceLayout({ collapsed={false} account={params.account} accounts={accounts} - user={data.session?.user ?? null} + user={data?.user ?? null} /> } > diff --git a/packages/features/team-accounts/src/components/settings/team-account-danger-zone.tsx b/packages/features/team-accounts/src/components/settings/team-account-danger-zone.tsx index f4c8fcee4..1bbc06bfb 100644 --- a/packages/features/team-accounts/src/components/settings/team-account-danger-zone.tsx +++ b/packages/features/team-accounts/src/components/settings/team-account-danger-zone.tsx @@ -47,14 +47,14 @@ export function TeamAccountDangerZone({ primaryOwnerUserId: string; }>) { - const { data: user, isLoading } = useUser(); + const { data: user } = useUser(); - if (isLoading) { + if (!user) { return ; } // Only the primary owner can delete the team account - const userIsPrimaryOwner = user?.id === primaryOwnerUserId; + const userIsPrimaryOwner = user.id === primaryOwnerUserId; if (userIsPrimaryOwner) { return ;