Added a check to ensure the user object is not null before accessing its properties. This prevents the application from crashing due to a TypeError when no user data is available in localStorage.