Ein Benutzer (DW_dev) meldet, dass Social Logins (Google, Discord, LinkedIn) auf Desktop-Geräten funktionieren, aber auf mobilen Geräten mit der Fehlermeldung csrf_detected fehlschlagen. Nach dem Redirect landet der Nutzer auf der Startseite, ist jedoch nicht eingeloggt. Die Logs zeigen wiederholt den CSRF-Fehler. Zunächst wird gefragt, ob es sich um eine Standard-Installation handelt (pfaffman), was bestätigt wird (DW_dev). Die Lösung findet DW_dev selbst: Ein benutzerdefiniertes JavaScript-Skript im Theme, das auf mobilen Geräten die Seite ständig neu lädt (window.location.replace), verursachte das Problem. Durch Entfernen dieses Skripts wurde der CSRF-Fehler behoben, da die Session- und CSRF-Token nun korrekt über den Redirect übertragen werden können.
I found the solution to the issue where social logins (Google, Discord, etc.) fail with csrf_detected on mobile devices, even though they work on PC.
The cause was in my theme:
A custom JavaScript script in the \u003chead\u003e section of the theme was constantly reloading the page (window.location.replace) on mobile devices.
This forced redirect destroyed the temporary CSRF token necessary for session validation after the Google/Discord callback.
Solution:
I removed the entire script for forcing the mobile view from the theme.
If you have similar issues and are using a custom theme, check if there are any scripts running that trigger redirects. That was the culprit in my case!