diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-05-04 13:17:22 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-05-04 13:17:22 +0700 |
| commit | 598815af1ca2c7b549a867f3673c127af3ea9deb (patch) | |
| tree | c512c8649a267a32e883e36fb2b971357b65d944 | |
| parent | 64a60cc9c6a836cc574036bd4998f16ea945f3c2 (diff) | |
product get server side with user token
| -rw-r--r-- | src/pages/shop/product/[slug].jsx | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx index 290529a7..5d706dec 100644 --- a/src/pages/shop/product/[slug].jsx +++ b/src/pages/shop/product/[slug].jsx @@ -5,14 +5,19 @@ import productApi from '@/lib/product/api/productApi' import PageNotFound from '@/pages/404' import dynamic from 'next/dynamic' import { useRouter } from 'next/router' +import cookie from 'cookie' const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout')) const Product = dynamic(() => import('@/lib/product/components/Product/Product')) export async function getServerSideProps(context) { const { slug } = context.query + const cookies = context.req.headers.cookie + const cookieObj = cookies ? cookie.parse(cookies) : {} + const auth = cookieObj.auth ? JSON.parse(cookieObj.auth) : {} + const authToken = auth?.token || '' - let product = await productApi({ id: getIdFromSlug(slug) }) + let product = await productApi({ id: getIdFromSlug(slug), headers: { Token: authToken } }) if (product?.length == 1) { product = product[0] const regexHtmlTags = /(<([^>]+)>)/gi @@ -47,8 +52,8 @@ export default function ProductDetail({ product }) { url: product?.image, width: 800, height: 800, - alt: product?.name, - }, + alt: product?.name + } ], type: 'product' }} |
