Improved redirect logic after logging in