Scrum4Me/app/(app)/products/[id]/layout.tsx
Madhura68 29ed4f2773 feat: show active product name in navbar, links to product page
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>
2026-04-26 17:56:50 +02:00

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}
</>
)
}