Are you wanting to show different content on the page depending on if the user is logged in or not as well?
If so, have you looked into any membership plugins? Most of them allow you to redirect users who aren’t logged in to a separate page asking them to login.
If the user is logged in, they’re allowed to access the page without any redirection.
If the content is the same, and the only thing you’re changing is the sidebar, the function I’ll give you will do the trick.
Let me know 🙂