Skip to content

Commit

Permalink
Merge pull request #25 from pixelmund/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
pixelmund authored Jan 20, 2022
2 parents d88836e + 095523e commit 16aef94
Show file tree
Hide file tree
Showing 17 changed files with 837 additions and 658 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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);
}
);
```
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte-kit-cookie-session",
"version": "1.4.0",
"version": "2.0.0",
"description": "⚒️ Encrypted 'stateless' cookie sessions for SvelteKit",
"repository": {
"type": "git",
Expand Down Expand Up @@ -34,14 +34,14 @@
"author": "pixelmund",
"license": "MIT",
"devDependencies": {
"@sveltejs/kit": "^1.0.0-next.111",
"@sveltejs/kit": "next",
"@types/cookie": "^0.4.1",
"@types/node": "^14.14.35",
"@types/node": "^17.0.10",
"loadr": "^0.1.1",
"rimraf": "^3.0.2",
"svelte": "^3.35.0",
"svelte": "^3.46.2",
"tsm": "^2.2.1",
"typescript": "^4.2.3",
"typescript": "^4.5.4",
"uvu": "^0.6.0-next.1"
}
}
Loading

0 comments on commit 16aef94

Please sign in to comment.