-3

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?

5
  • 2
    You can stay logged in on as many devices/browsers as you want. On user level all things you store in one place will be available everywhere else. It is, however, not possible to share a PHP session. But in Drupal there is not very much which depends on the PHP session. Can you be more specific what you mean by become a little hassle?
    – 4uk4
    Commented Apr 20, 2022 at 19:25
  • Drupal doesn't destroy the existing session; it just copies the data from the existing session to the new one. Otherwise, it would have a \Drupal::service('session')->migrate(TRUE); line. (migrate() uses FALSE as default value for $destroy, the first parameter.)
    – avpaderno
    Commented Apr 21, 2022 at 10:40
  • If you mean that users who log in using a different device are logged out from the device they were previously using, that could be the effect calling 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.
    – avpaderno
    Commented Apr 21, 2022 at 10:51
  • \Drupal::service('session')->migrate() calls NativeSessionStorage::regenerate(), which calls session_regenerate_id(), which could cause a lost session, when using a mobile or Wi-Fi network.
    – avpaderno
    Commented Apr 21, 2022 at 10:53
  • What Drupal is doing here is migrating the anonymous session to the authenticated session. You can't loose other sessions, this only affects the session data the user might have generated while visiting the site on a new browser without logging in right away.
    – 4uk4
    Commented Apr 21, 2022 at 12:45

1 Answer 1

2

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.

1
  • 4
    This isn't a Drupal limitation. This is just how browsers and cookies work.
    – mona lisa
    Commented Apr 20, 2022 at 21:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.