You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the current version, when a user hits refresh on a product page they lose access to the state. The correct behavior should be that on refresh, the user should generally get back to the same state.
This is a technical debt, as currently it checks that if we do not have access to the product.name (through optional chaining).
If we do not have access to the product's name, consequently we also do not have access to the product. This is a way to check if state is lost on page refresh.
Issue: how this is handled
The issue is that we simply re-route the user back to the home route (re-navigate them to the home page) in this scenario.
The problem with this is if users wish to share URLs to products, they wouldn't be able to. Other users cannot share other product URLS because they do not have access to the product state. They would have to access the specific product by clicking on its ProductCard on the home-page.
The text was updated successfully, but these errors were encountered:
Create the route that returns the price object for the specific product
Note: how the filtering happens within the POST Route Handler rather than the client-side product page to improve load times.
import{NextResponse}from"next/server";importStripefrom"stripe";exportasyncfunctionPOST(request){constbody=awaitrequest.json();if(body.lineItems.length===0){returnnewResponse('Error',{status: 405,});}// Destructure out price_id from the request bodyconst{ price_id }=body.lineItems;try{// Initialize Stripeconststripe=newStripe(process.env.STRIPE_SECRET??'',{apiVersion: '2020-08-27'});// Fetch a list of pricesconstres=awaitstripe.prices.list({expand: ['data.product']});console.log(res);// Access price list data within the response (an array)constdataArr=res.data;// Filter through by price_idconstprice=dataArr.filter(item=>item.id===price_id);returnNextResponse.json({ price });}catch(err){console.log("-------- error on product page load --------");console.log(err);returnnewResponse('Error',{status: 500,});}}
Back to the Product Page
Load the product in, access the data, and destructure the information we need to dynamically render the sub-page:
In the current version, when a user hits refresh on a product page they lose access to the state. The correct behavior should be that on refresh, the user should generally get back to the same state.
The stop-gap solution in
/app/product/page.js
:This is a technical debt, as currently it checks that if we do not have access to the
product.name
(through optional chaining).If we do not have access to the product's name, consequently we also do not have access to the product. This is a way to check if state is lost on page refresh.
Issue: how this is handled
The issue is that we simply re-route the user back to the home route (re-navigate them to the home page) in this scenario.
The problem with this is if users wish to share URLs to products, they wouldn't be able to. Other users cannot share other product URLS because they do not have access to the product state. They would have to access the specific product by clicking on its
ProductCard
on the home-page.The text was updated successfully, but these errors were encountered: