-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from pixelmund/v2
V2
- Loading branch information
Showing
17 changed files
with
837 additions
and
658 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,11 @@ The seal stored on the client contains the session data, not your server, making | |
|
||
--- | ||
|
||
## Upgrading from v1 to v2 | ||
|
||
Please use any version above `@sveltejs/[email protected]`, all older versions are not compatible with v2 anymore. Stick to `1.4.0` if you like to use older versions of `kit`. | ||
There are no major breaking changes, besides some internal refactoring and switching from JS Proxy to Getters/Setters which should end up in a better performance. We also only decrypt the session data now if you access the session.data. Also the session data returns undefined now if not existing instead of an empty object. | ||
|
||
## Installation | ||
|
||
Install into `dependencies` | ||
|
@@ -73,11 +78,11 @@ export const handle = handleSession( | |
{ | ||
secret: "SOME_COMPLEX_SECRET_AT_LEAST_32_CHARS", | ||
}, | ||
({ request, resolve }) => { | ||
// request.locals is populated with the session `request.locals.session` | ||
({ event, resolve }) => { | ||
// event.locals is populated with the session `event.locals.session` | ||
|
||
// Do anything you want here | ||
return resolve(request); | ||
return resolve(event); | ||
} | ||
); | ||
``` | ||
|
@@ -132,8 +137,8 @@ Notes: | |
```js | ||
/** @type {import('@sveltejs/kit').RequestHandler} */ | ||
export async function post({ locals, body }) { | ||
locals.session.data = body; | ||
export async function post({ locals, request }) { | ||
locals.session.data = { loggedIn: true }; | ||
|
||
return { | ||
body: locals.session.data, | ||
|
@@ -149,7 +154,7 @@ export async function post({ locals, body }) { | |
```js | ||
/** @type {import('@sveltejs/kit').RequestHandler} */ | ||
export async function get({ locals, body }) { | ||
export async function get({ locals, request }) { | ||
// console.log(locals.session) will be empty | ||
|
||
// Access your data via locals.session.data -> this should always be an object. | ||
|
@@ -186,7 +191,7 @@ export async function del({ locals }) { | |
```js | ||
/** @type {import('@sveltejs/kit').RequestHandler} */ | ||
export async function put({ locals, body }) { | ||
export async function put({ locals, request }) { | ||
locals.session.refresh(/** Optional new expiration time in days */); | ||
|
||
return { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.