Prerequisites:
1. I assume you have added your primary and same Apple ID / iCloud Account on your respective Mac and iPhone.
2. You have enabled iCloud Sync for Messages App on your iPhone and Mac in iCloud Settings.
3. You are using the latest release of macOS operating system, the latest release of iOS operating System and latest release Safari Browser.
Once above prerequisites are met we can proceed further…
Note: You can autofill security codes from your iPhone to Safari on Mac. This is Safari only feature.
To set up Text Message Forwarding on your iPhone follow below steps:
Step 01: On your iPhone, go to Settings > Messages > Text Message Forwarding.
Step 02: Tap slider to make it green to select your choice of Mac.
You are done,
When you select text box field while entering details on your Safari on Mac respective OTP will be populated automatically with a click of a button.
Hope it helps,
Thanks & Regards
Mandar Apte