2FA codes not received on Messages in macOS
Sounds like you are receiving/sending iMessages on your Mac, but not SMS (used for 2FA).
In your iPhone settings, go to “Messages”, and setup “Text Message Forwarding” to your Mac.
More info on Apple Support.