In this episode, we tackle a bug that pops up when a user isn't logged in. After logging out, you might have noticed that trying to browse the forum caused an error—specifically because our code was trying to access properties of a user object that doesn't exist when you're not authenticated.
We walk through the process of making our code more robust by using the null-safe operator, ensuring that if a user isn't signed in, we don't run into errors. We start by fixing this issue on the discussion resource, making sure it gracefully handles the case where there's no logged-in user. Then we check the same thing for posts and any other relevant resources.
After these fixes, we test it out: as a logged-out user, you can browse discussions, use filters, and search functionality works—just without any actions that require login. Everything looks smooth and error-free, making the app much more user-friendly for everyone, authenticated or not.