avoid too many duplicate requireUserInServerComponent requests for each page+layout
This commit is contained in:
@@ -22,13 +22,14 @@ export default async function AnalysisResultsPage({
|
||||
id: string;
|
||||
}>;
|
||||
}) {
|
||||
const account = await loadCurrentUserAccount();
|
||||
|
||||
const { id: analysisOrderId } = await params;
|
||||
|
||||
const analysisResponse = await loadUserAnalysis(Number(analysisOrderId));
|
||||
const [{ account }, analysisResponse] = await Promise.all([
|
||||
loadCurrentUserAccount(),
|
||||
loadUserAnalysis(Number(analysisOrderId)),
|
||||
]);
|
||||
|
||||
if (!account?.id || !analysisResponse) {
|
||||
if (!account?.id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -37,6 +38,10 @@ export default async function AnalysisResultsPage({
|
||||
action: PageViewAction.VIEW_ANALYSIS_RESULTS,
|
||||
});
|
||||
|
||||
if (!analysisResponse) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader />
|
||||
|
||||
@@ -168,7 +168,7 @@ async function sendAnalysisPackageOrderEmail({
|
||||
}
|
||||
|
||||
export async function processMontonioCallback(orderToken: string) {
|
||||
const account = await loadCurrentUserAccount();
|
||||
const { account } = await loadCurrentUserAccount();
|
||||
if (!account) {
|
||||
throw new Error("Account not found in context");
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export const generateMetadata = async () => {
|
||||
};
|
||||
|
||||
async function OrderAnalysisPage() {
|
||||
const account = await loadCurrentUserAccount();
|
||||
const { account } = await loadCurrentUserAccount();
|
||||
if (!account) {
|
||||
throw new Error('Account not found');
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export const generateMetadata = async () => {
|
||||
async function UserHomePage() {
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
const account = await loadCurrentUserAccount();
|
||||
const { account } = await loadCurrentUserAccount();
|
||||
const api = createAccountsApi(client);
|
||||
const bmiThresholds = await api.fetchBmiThresholds();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user