avoid too many duplicate requireUserInServerComponent requests for each page+layout

This commit is contained in:
2025-09-10 00:12:57 +03:00
parent 2aad0329f3
commit 312027b9ed
13 changed files with 28 additions and 37 deletions

View File

@@ -38,8 +38,7 @@ export async function handleAddToCart({
countryCode: string;
}) {
const supabase = getSupabaseServerClient();
const user = await requireUserInServerComponent();
const account = await loadCurrentUserAccount();
const { account, user } = await loadCurrentUserAccount();
if (!account) {
throw new Error('Account not found');
}
@@ -70,8 +69,7 @@ export async function handleDeleteCartItem({ lineId }: { lineId: string }) {
const supabase = getSupabaseServerClient();
const cartId = await getCartId();
const user = await requireUserInServerComponent();
const account = await loadCurrentUserAccount();
const { account, user } = await loadCurrentUserAccount();
if (!account) {
throw new Error('Account not found');
}
@@ -96,8 +94,7 @@ export async function handleNavigateToPayment({
paymentSessionId: string;
}) {
const supabase = getSupabaseServerClient();
const user = await requireUserInServerComponent();
const account = await loadCurrentUserAccount();
const { account, user } = await loadCurrentUserAccount();
if (!account) {
throw new Error('Account not found');
}
@@ -137,8 +134,7 @@ export async function handleLineItemTimeout({
lineItem: StoreCartLineItem;
}) {
const supabase = getSupabaseServerClient();
const user = await requireUserInServerComponent();
const account = await loadCurrentUserAccount();
const { account, user } = await loadCurrentUserAccount();
if (!account) {
throw new Error('Account not found');
}