refactor: resolve shopping loading issue

This commit is contained in:
2025-05-14 19:32:08 +05:30
parent 668900661d
commit 6b0f177858

View File

@@ -22,15 +22,22 @@ const ShoppingCart = () => {
const { formatPrice } = useCurrency(); const { formatPrice } = useCurrency();
const getCart = async () => { const getCart = async () => {
token = localStorage.getItem("token") const token = localStorage.getItem("token");
if (token == null) {
setCartItems([]) if (!token) {
} else { console.log("User not logged in, setting empty cart");
setCartItems([]);
return;
}
try {
const response = await authAxios.get("/orders/cart/"); const response = await authAxios.get("/orders/cart/");
setCartItems(response.data); setCartItems(response.data);
} catch (error) {
console.error("Error fetching cart:", error);
setCartItems([]);
} }
}; };
useEffect(() => { useEffect(() => {
getCart(); getCart();
}, []); }, []);