17 lines
445 B
TypeScript
17 lines
445 B
TypeScript
import { cache } from 'react';
|
|
import { medusaClient } from '@/lib/config';
|
|
import { PricedProduct } from '@medusajs/medusa/dist/types/pricing';
|
|
|
|
export const getProductByHandle = cache(async function (
|
|
handle: string,
|
|
): Promise<{ product: PricedProduct }> {
|
|
const product = await medusaClient.products
|
|
.list({ handle })
|
|
.then(({ products }) => products[0])
|
|
.catch((err) => {
|
|
throw err;
|
|
});
|
|
|
|
return { product };
|
|
});
|