Score:-2

How to make users stay logged in across devices?

pe flag

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?

4uk4 avatar
cn flag
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?
apaderno avatar
us flag
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.)
apaderno avatar
us flag
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()`](https://www.php.net/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.*
apaderno avatar
us flag
`\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.
4uk4 avatar
cn flag
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.
Score:2
id flag

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.

id flag
This isn't a Drupal limitation. This is just how browsers and cookies work.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.