Invalid CSRF token after being logged out automatically

I know this has been brought up many times before but somehow there must be a more elegant solution than clearing sessions cookies or reloading or whatever. When the system logs me out automatically, it shows the login form with localized language:
Bildschirmfoto 2023-10-30 um 12.17.54

If I try to login then, it shows the error:
Bildschirmfoto 2023-10-30 um 12.18.13

I have to reload to be able to log in, and then it switches the language to English:
Bildschirmfoto 2023-10-30 um 12.18.19

It might be because the default primary language header in my Firefox is set to en-US.

But anyway, it seems like it has something to do with session cookies but this error shouldn’t happen in the first place.

Is your project open in multiple browser tabs/windows when this happens?

Nope, just one browser, one single session. If there is no activity, it logs me out automatically, and then the error comes up if I try to log in. I can only log in after reloading the login form.

Hey,
we have the same problem if one of our users keeps the tab open for a long time or pins it.

A reload before login fixes it but i would be nice if it was not necessary.

I also have the same problem. Both on desktop PC and on smartphone. Tab is open for a long time in the background. After automatic logout, logging in again is only possible with a page reload. I use Chrome.