How can I stop the hook from breaking the login/logout function?

If this is in functions.php, then you don’t need a hook for this at all, because the functions.php file is loaded right where you want it. So just unwrap this and move it out of a function call altogether; i.e., still in your functions.php, but not attached to any specific hook.

Or, use the after_setup_theme hook if you want to delay it slightly.