diff --git a/pages/expense.tsx b/pages/expense.tsx index 41d3a65dae6..5106cb11fcd 100644 --- a/pages/expense.tsx +++ b/pages/expense.tsx @@ -77,6 +77,10 @@ const getPageMetadata = (intl, legacyExpenseId, expense) => { } }; +const isValidCollectiveSlug = (collectiveSlug: string, expense) => { + return [expense.account.slug, expense.account.parent?.slug].filter(Boolean).includes(collectiveSlug); +}; + // next.js export // ts-unused-exports:disable-next-line export default function ExpensePage(props: InferGetServerSidePropsType) { @@ -106,7 +110,7 @@ export default function ExpensePage(props: InferGetServerSidePropsType; } else if (!data.expense) { return ; - } else if (!data.expense.account || props.collectiveSlug !== data.expense.account.slug) { + } else if (!data.expense.account || !isValidCollectiveSlug(collectiveSlug, data.expense)) { return ; } }