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.
This commit is contained in:
@@ -30,12 +30,12 @@ export const loadTeamWorkspace = cache(async (accountSlug: string) => {
|
|||||||
accountResult,
|
accountResult,
|
||||||
accountsResult,
|
accountsResult,
|
||||||
{
|
{
|
||||||
data: { session },
|
data: { user },
|
||||||
},
|
},
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
accountPromise,
|
accountPromise,
|
||||||
accountsPromise,
|
accountsPromise,
|
||||||
client.auth.getSession(),
|
client.auth.getUser(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (accountResult.error) {
|
if (accountResult.error) {
|
||||||
@@ -63,6 +63,6 @@ export const loadTeamWorkspace = cache(async (accountSlug: string) => {
|
|||||||
return {
|
return {
|
||||||
account: accountData,
|
account: accountData,
|
||||||
accounts: accountsResult.data,
|
accounts: accountsResult.data,
|
||||||
session,
|
user,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export const generateMetadata = async () => {
|
|||||||
async function TeamAccountBillingPage({ params }: Params) {
|
async function TeamAccountBillingPage({ params }: Params) {
|
||||||
const workspace = await loadTeamWorkspace(params.account);
|
const workspace = await loadTeamWorkspace(params.account);
|
||||||
const accountId = workspace.account.id;
|
const accountId = workspace.account.id;
|
||||||
|
|
||||||
const [subscription, customerId] =
|
const [subscription, customerId] =
|
||||||
await loadTeamAccountBillingPage(accountId);
|
await loadTeamAccountBillingPage(accountId);
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function TeamWorkspaceLayout({
|
|||||||
collapsed={false}
|
collapsed={false}
|
||||||
account={params.account}
|
account={params.account}
|
||||||
accounts={accounts}
|
accounts={accounts}
|
||||||
user={data.session?.user ?? null}
|
user={data?.user ?? null}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -47,14 +47,14 @@ export function TeamAccountDangerZone({
|
|||||||
|
|
||||||
primaryOwnerUserId: string;
|
primaryOwnerUserId: string;
|
||||||
}>) {
|
}>) {
|
||||||
const { data: user, isLoading } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
if (isLoading) {
|
if (!user) {
|
||||||
return <LoadingOverlay fullPage={false} />;
|
return <LoadingOverlay fullPage={false} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only the primary owner can delete the team account
|
// Only the primary owner can delete the team account
|
||||||
const userIsPrimaryOwner = user?.id === primaryOwnerUserId;
|
const userIsPrimaryOwner = user.id === primaryOwnerUserId;
|
||||||
|
|
||||||
if (userIsPrimaryOwner) {
|
if (userIsPrimaryOwner) {
|
||||||
return <DeleteTeamContainer account={account} />;
|
return <DeleteTeamContainer account={account} />;
|
||||||
|
|||||||
Reference in New Issue
Block a user