Sub-layout sets product in Zustand store; NavBar reads it. getAccessibleProduct wrapped with React cache to avoid double DB call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
696 B
TypeScript
25 lines
696 B
TypeScript
import { redirect, notFound } from 'next/navigation'
|
|
import { getSession } from '@/lib/auth'
|
|
import { getAccessibleProduct } from '@/lib/product-access'
|
|
import { SetCurrentProduct } from '@/components/shared/set-current-product'
|
|
|
|
interface Props {
|
|
children: React.ReactNode
|
|
params: Promise<{ id: string }>
|
|
}
|
|
|
|
export default async function ProductLayout({ children, params }: Props) {
|
|
const { id } = await params
|
|
const session = await getSession()
|
|
if (!session.userId) redirect('/login')
|
|
|
|
const product = await getAccessibleProduct(id, session.userId)
|
|
if (!product) notFound()
|
|
|
|
return (
|
|
<>
|
|
<SetCurrentProduct id={id} name={product.name} />
|
|
{children}
|
|
</>
|
|
)
|
|
}
|