feat: session support #315
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #58
This PR adds basic session support. Sessions are sealed (encrypted and signed with a private key) in cookies using iron-webcrypto (thanks @brc-dd ❤️) and uncrypto to work out of with Node.js and other environments.
The encrypted session is carried over cookies, therefore no server storage is required for session support.
Multiple session support is also possible with this implementation and custom
nameoption (default ish3and used for cookie name as well )Default cookie options are secure, httpOnly with path of
/(can be configured)Exposed utils:
useSession: Initializes session and returns an{ data, id, update(val), clear() }interface to manage session. WrappinggetSession,updateSessionandclearSessiongetSession: Treis to reuse or otherwise init an empty session for userupdateSession: Updates session both in cookie and context. Also initializes if not initialized yetclearSession: Clears session from both cookie and contextSimple usage:
Known issues:
set-cookieheader with same name #316)