Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Make mandatory session properties immutable #54

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

interpretor
Copy link
Contributor

Closes #2.

Checklist:

  • issue number linked above after pound (#)
    • replace "Closes " with "Contributes to" or other if this PR does not close the issue
  • manually checked my feature / checking not applicable
  • wrote tests / testing not applicable
  • attached screenshots / screenshot not applicable

Attach a session object to the event context with mandatory immutable properties id, createdAt and ip.
When the user wants to reassign those properties, an error is thrown. This is better than just doing nothing, because the user knows that he did something wrong in saving properties to the session in the event context.

ip?: string;
readonly id: string;
readonly createdAt: Date;
readonly ip?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and, sorry to kind of push this in here, but as we're already working on the Session interface: Would you consider adapting the h3 event context as done here:
https://github.com/sidebase/nuxt-prisma/blob/b1ffd717cf1061215498fa8e9b90ce62cac8b494/src/runtime/server/middleware/prisma.ts#L7-L11

whuile you're add it? This way, typing for the end-user should improve when they access event.context.session

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it, but somehow the types aren't available when packed and imported as module in a project. Any suggestions?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better store session-meta-data in session object
2 participants