This may not be possible, but when certain conditions happen, I'd like to modify the session data of certain logged in users (flagging that some extra logic needs to run the next time they load a page).
Is there a way to access the session of a user by their ID?
tldr; Query
Session
model, then modify matching sessions viaSessionStore
.Your question is twofold, how to get session of a user, and how to modify data of arbitrary sessions (possibly outside of view).
Get all logged in user sessions
Since the session data is stored in an encoded form, I suggest getting all non-expired sessions, iterate over them, decode the data and check if associated with a user. Collect matching session keys to act on later.
Modify sessions outside of view
Although the scenario is not explicitely stated, the docs do mention how to access sessions, without
request
context. Basically,SessionStore
must be used to modify the session (which in turn will store the new data inSession
)