import Image from 'next/image'; import Link from 'next/link'; import { getCustomerOrders } from 'lib/shopify'; import Price from 'components/price'; import Divider from 'components/divider'; import { Button } from 'components/button'; export const runtime = 'edge'; export default async function AccountPage() { // if (!access) { // redirect('/logout'); // } // if (access === 'denied') { // redirect('/logout'); // } // // const customerAccessToken = access; // // //this is needed b/c of strange way server components handle redirects etc. // //see https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#redirecting // //can only redirect outside of try/catch! // let success = true; // let errorMessage; // let customerData; // let orders; // // try { // const responseCustomerDetails = await shopifyCustomerFetch({ // customerToken: customerAccessToken, // query: CUSTOMER_DETAILS_QUERY, // tags: [TAGS.customer] // }); // const userDetails = responseCustomerDetails.body; // if (!userDetails) { // throw new Error('Error getting actual user data Account page.'); // } // customerData = userDetails?.data?.customer; // orders = customerData?.orders?.edges; // //console.log ("Details",orders) // } catch (e) { // //they don't recognize this error in TS! // //@ts-ignore // errorMessage = e?.error?.toString() ?? 'Unknown Error'; // console.log('error customer fetch account', e); // if (errorMessage !== 'unauthorized') { // throw new Error('Error getting actual user data Account page.'); // } else { // console.log('Unauthorized access. Set to false and redirect'); // success = false; // } // } // if (!success && errorMessage === 'unauthorized') redirect('/logout'); // // revalidateTag('posts') // Update cached posts //FIX const orders = await getCustomerOrders(); return (

Orders

{orders.map((order, index) => (
{order.lineItems.slice(0, 2).map((lineItem, index) => (
{lineItem?.image?.altText}

{lineItem.title}

))}

{order.lineItems.length} item{order.lineItems.length > 1 && 's'}

Order {order.name}

))}
); }