[solved] 2fa not working anymore after reinstall

"Nextcloud version (eg, 18.0.2):
Operating system and version (eg, Ubuntu 20.04): official docker ‘production’ armv7
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.38
PHP version (eg, 7.1): 7.4.14

The issue you are facing:
I was previously using the docker version from linuxserver but had an issue with it so I moved to the official docker version on the same database.
After a bit of tuning :grin: everything is now working fine except that the 2fa I had before is not working anymore:
When I try to login, I get a message saying that 2fa is enforced but not configured and I’m asked to provide a backup code.
So I provide one and go to the security parameters but the only option I get there is to regenerate backup codes and I can’t configure anything. There’s no qr code showing…
How can I get rid of that?
(To make it clear, I want to get 2FA working, not remove it)

The log contains lines saying that the 2fa auth provider failed to load and a line saying

[index] Error: Exception: Argument 1 passed to OC\Core\Controller\WebAuthnController::finishAuthentication() must be of the type string, null given, called in /var/www/html/lib/private/AppFramework/Http/Dispatcher.php on line 169 at <<closure>>

0. /var/www/html/lib/private/AppFramework/App.php line 152
   OC\AppFramework\Http\Dispatcher->dispatch(OC\Core\Controller\WebAuthnController {}, "finishAuthentication")
1. /var/www/html/lib/private/Route/Router.php line 309
   OC\AppFramework\App::main("OC\\Core\\Contr ... r", "finishAuthentication", OC\AppFramework\ ... {}, {_route: "core.W ... "})
2. /var/www/html/lib/base.php line 1008
3. /var/www/html/index.php line 37

POST /login/webauthn/finish
from at 2021-01-17T18:26:44+00:00

config.php file contains:

 'twofactor_enforced' => 'true',
  'twofactor_enforced_groups' =>
  array (
    0 => 'admin',
  'twofactor_enforced_excluded_groups' =>
  array (

EDIT: added log

At the moment, to avoid getting asked for a backup code each time I connect, the only way I found was to stop enforcing 2FA in config.php and change manually the database:
update oc_twofactor_providers set enabled = '0';

I don’t know how to reset the 2FA to a working state…

Finally got it working this way:

  1. Totally uninstall the totp application
  2. Truncate all the oc_twofactors tables in the database
    Here, no more totp, you can connect without 2fa
  3. Reinstall the totp application
  4. Go to admin/security and setup totp like if it was the 1rst time…