Adding logic to check if user is logged in and redirect to login page if not.