This question already has an answer here:
I noticed that when I enabled two-factor authentication for my Apple ID and have handoff turned on, the code pops up on the mac where I'm seeking the two factor. Seems like it renders the two-factor worthless. Isn't the point it have it go to another device, separate from the login device?
I guess the obvious solution is to not have handoff on the mac?