From 5d0975be8accd733e2ed909dba85f04d6d1042f5 Mon Sep 17 00:00:00 2001 From: Jorge Moya Date: Mon, 8 Jul 2024 11:43:49 -0500 Subject: [PATCH] fix(core): use customerId in product api (#1071) --- .changeset/fuzzy-ties-switch.md | 5 +++++ core/app/api/product/[id]/route.ts | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 .changeset/fuzzy-ties-switch.md diff --git a/.changeset/fuzzy-ties-switch.md b/.changeset/fuzzy-ties-switch.md new file mode 100644 index 000000000..106ad3a61 --- /dev/null +++ b/.changeset/fuzzy-ties-switch.md @@ -0,0 +1,5 @@ +--- +"@bigcommerce/catalyst-core": patch +--- + +Use customerId in product API to get correct product information. diff --git a/core/app/api/product/[id]/route.ts b/core/app/api/product/[id]/route.ts index e8bcaacc9..8cf573f3e 100644 --- a/core/app/api/product/[id]/route.ts +++ b/core/app/api/product/[id]/route.ts @@ -3,6 +3,7 @@ */ import { NextRequest, NextResponse } from 'next/server'; +import { getSessionCustomerId } from '~/auth'; import { getChannelIdFromLocale } from '~/channels.config'; import { client } from '~/client'; import { graphql } from '~/client/graphql'; @@ -22,6 +23,8 @@ const GetProductQuery = graphql( ); export const GET = async (request: NextRequest, { params }: { params: { id: string } }) => { + const customerId = await getSessionCustomerId(); + if (request.headers.get('x-catalyst-product-sheet') !== 'true') { return NextResponse.json( { status: 'error', message: 'Endpoint only available for product-sheet component.' }, @@ -48,6 +51,7 @@ export const GET = async (request: NextRequest, { params }: { params: { id: stri document: GetProductQuery, variables: { productId: Number(id), optionValueIds }, channelId: getChannelIdFromLocale(locale), + customerId, }); return NextResponse.json(data.site.product);