Score:0

Logged in user data, after logout

US flag

I need the ID of the logged in user, after logging out. I tried to use a session variable, but all data is lost on exit. Is there any method to use, other than the query parameter?

┌──────────────┐                        ┌──────────────┐
│              │                        │              │
│  Page        │       ┌────────┐       │  Page        │
│              │       │        │       │              │
│  generation  │ ────► │ logout │ ────► │  generation  │
│              │       │        │       │              │
│  (UID: ?)    │       └────────┘       │  (UID: 0)    │
│              │                        │              │
└──────────────┘                        └──────────────┘

What is original user ID?

Kevin avatar
in flag
I don't understand - a logged out user only has an ID of 0. You would need to do some work in the user logout event/hook - but I am not sure what you're trying to do.
Kurucz István avatar
md
@Kevin Please see edited question.
Score:4
um flag

user_logout() contains \Drupal::service('session_manager')->destroy(); there is no chance of recovering the session after that. You need to set a cookie with the user id of the currently logged in user in hook_user_logout. Luckily the hook gets the $user as argument.

I sit in a Tesla and translated this thread with Ai:

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.