Move rebuild_auth functionality to a standalone hook