0

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?

2
  • 1
    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.
    – Kevin
    Jan 9, 2023 at 0:42
  • @Kevin Please see edited question. Jan 9, 2023 at 7:43

1 Answer 1

4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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