https://api.drupal.org/api/drupal/core!modules!user!user.module/function/user_login_finalize/9.2.x regenerates the sessions each time the user logs in. This can become a little hassle if user for instance switch between working between different deices (e.g. mobile + laptop). Is there any way to make the user stay logged in across devices?
1 Answer
No, not really. There is no practical way to share the same session between devices or between different browsers on the same device.
If you wish to ease transition between devices, a single sign on (SSO) integration that uses popular account sources (like for example, Google) may improve the user experience. There are various options for SSO.
-
4This isn't a Drupal limitation. This is just how browsers and cookies work. Commented Apr 20, 2022 at 21:32
\Drupal::service('session')->migrate(TRUE);
line. (migrate()
usesFALSE
as default value for$destroy
, the first parameter.)session_regenerate_id()
has: Currently, session_regenerate_id does not handle an unstable network well, e.g. Mobile and WiFi network. Therefore, you may experience a lost session by calling session_regenerate_id.\Drupal::service('session')->migrate()
callsNativeSessionStorage::regenerate()
, which callssession_regenerate_id()
, which could cause a lost session, when using a mobile or Wi-Fi network.