In this episode, we tackle a bug that happens when non-authenticated users (guests) try to check out. If you're not signed in and go straight to the checkout page, you'll notice an error appears—it's trying to loop through user shipping addresses, but since you're not logged in, there aren't any!
We walk through a simple fix: instead of always trying to show the shipping address dropdown, we add an if
statement to only display it if the user has shipping addresses available. This makes sure that guests won't see an error, and even logged-in users won't see the dropdown unless they actually have addresses saved.
After adding this check, we test it out to make sure the error is gone for both guests and users without shipping addresses. It's a quick and easy tweak, but it smooths out a rough edge in the checkout flow before we move on to the next feature.