Skip to content

🐞 Bug Report: getUserSession(event) returns partial session in cachedEventHandler #431

@mrkaashee

Description

@mrkaashee

When using getUserSession(event) inside a cachedEventHandler, the returned session object only includes the id:

// inside cachedEventHandler
const session = await getUserSession(event);
console.log(session);
// Output: { id: '99ca50c6-297f-429c-8f53-5903d6ecd74b' }

However, in defineEventHandler, the same call returns the full session with the user object populated:

// inside defineEventHandler
const session = await getUserSession(event);
console.log(session);
// Output includes: session.user = { id, username, roles, etc. }

Expected Behavior

Calling getUserSession(event) should return the same structure and data, regardless of whether the handler is wrapped in defineEventHandler or cachedEventHandler.

Actual Behavior

  • In cachedEventHandler, session.user is missing.

  • In defineEventHandler, session.user is present.

Notes

  • We're not caching session data.

  • Session is being retrieved solely to enrich or filter unrelated cached data.

  • The inconsistency leads to partial functionality or the need for workarounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions