Normally, when you install the 2FA, the website (let's say an exchange) provides a private key.
If you forgot to write down the key, then turn off the 2FA and then turn it on again, and off course when you turn it back on, you write down the private key and keep it in a safe place.