-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: session support #315
Conversation
Codecov Report
@@ Coverage Diff @@
## main #315 +/- ##
==========================================
- Coverage 77.27% 73.66% -3.62%
==========================================
Files 21 22 +1
Lines 1725 1868 +143
Branches 287 287
==========================================
+ Hits 1333 1376 +43
- Misses 392 492 +100
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Seems to me, there is an export missing for one of the types
|
My impression is that the TS community likes to keep their types implicit in order to minimize the potential maintenance overhead of explicit (and published) types. If you want to explicitly capture/name the type: import { updateSession } from "h3";
type Holder = {
count: number;
};
type HolderUpdate = (Parameters<typeof updateSession<Holder>>)[2]; TypeScript Handbook: |
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
name
option (default ish3
and 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
,updateSession
andclearSession
getSession
: 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-cookie
header with same name #316)