Cloudflared with HA 2FA is not working properly

My Home Assistant setup works perfectly through Cloudflare until I enable 2FA in Home Assistant itself. Once 2FA is enabled, remote access becomes nearly impossible.

Setup : Home Assistant running in a VM on a Synology NAS

What works:

  • Without HA 2FA enabled: everything works perfectly
  • With HA 2FA enabled:
    • Local network login works correctly
    • Remote login through Cloudflare fails after entering the 2FA code
      Error message:

      Unable to connect to Home Assistant.
      Retrying in 56 seconds...

Extra:

  • Time is correctly synchronized on:
    • Phone
    • Browser/device
    • VM
    • Home Assistant
  • I would prefer to use Home Assistant’s built-in 2FA instead of Cloudflare Access rules, because Cloudflare authentication works in the browser but not properly in the Android app.

Has anyone experienced this or found a reliable solution?