First, login to your Nextcloud account and navigate to the Name Icon > Settings page in the upper righthand corner:
On the Settings page, click Security in the lefthand menu:
Click ‘Enable TOTP’, and a code and QR image will appear. Using an authenticator app on your computer or smartphone (see below for some recommendations), either scan the QR code or enter the TOTP secret.
After creating a new entry in your authenticator app, use your app to generate a one-time code and enter it into the verification box in Nextcloud. This will complete verification and two factor authentication will be enabled on your account.
The next time you or anyone else tries logging into your account, this dialog will appear after entering the password asking for a new code from your authenticator app:
Aegis Authenticator (Free; Android) - https://getaegis.app/
Bitwarden Authenticator (Paid only; Most platforms) - https://bitwarden.com/help/bitwarden-authenticator/