Backport to 2.8.x: Infinite login request loop in web app after token timeout

Backport the fix from #3235 (closed) to the release/v2.8.x branch, so that it will be included in the 2.8.x frontend release.