@remix-run/session-middleware 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -7
- package/dist/lib/session.d.ts.map +1 -1
- package/dist/lib/session.js +2 -0
- package/package.json +5 -5
- package/src/lib/session.ts +2 -0
package/README.md
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
# session-middleware
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Session middleware for Remix using signed cookies. It loads session state from incoming requests, exposes it on `context.session`, and persists updates automatically.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Session Lifecycle Handling** - Reads and saves session state per request
|
|
8
|
+
- **Context Integration** - Exposes session APIs directly on request context
|
|
9
|
+
- **Secure Cookie Support** - Designed for signed session cookies
|
|
4
10
|
|
|
5
11
|
## Installation
|
|
6
12
|
|
|
7
13
|
```sh
|
|
8
|
-
npm
|
|
14
|
+
npm i remix
|
|
9
15
|
```
|
|
10
16
|
|
|
11
17
|
## Usage
|
|
12
18
|
|
|
13
19
|
```ts
|
|
14
|
-
import { createRouter } from '
|
|
15
|
-
import { createCookie } from '
|
|
16
|
-
import { createCookieSessionStorage } from '
|
|
17
|
-
import { session } from '
|
|
20
|
+
import { createRouter } from 'remix/fetch-router'
|
|
21
|
+
import { createCookie } from 'remix/cookie'
|
|
22
|
+
import { createCookieSessionStorage } from 'remix/session/cookie-storage'
|
|
23
|
+
import { session } from 'remix/session-middleware'
|
|
18
24
|
|
|
19
25
|
let sessionCookie = createCookie('__session', {
|
|
20
26
|
secrets: ['s3cr3t'], // session cookies must be signed!
|
|
@@ -48,7 +54,7 @@ Note: The session cookie must be signed for security. This prevents tampering wi
|
|
|
48
54
|
A basic login/logout flow could look like this:
|
|
49
55
|
|
|
50
56
|
```ts
|
|
51
|
-
import * as res from '
|
|
57
|
+
import * as res from 'remix/fetch-router/response-helpers'
|
|
52
58
|
|
|
53
59
|
router.get('/login', ({ session }) => {
|
|
54
60
|
let error = session.get('error')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/lib/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/lib/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,GAAG,UAAU,CA8BzF"}
|
package/dist/lib/session.js
CHANGED
|
@@ -22,6 +22,8 @@ export function session(sessionCookie, sessionStorage) {
|
|
|
22
22
|
}
|
|
23
23
|
let setCookieValue = await sessionStorage.save(session);
|
|
24
24
|
if (setCookieValue != null) {
|
|
25
|
+
// make sure the response is mutable
|
|
26
|
+
response = new Response(response.body, response);
|
|
25
27
|
response.headers.append('Set-Cookie', await sessionCookie.serialize(setCookieValue));
|
|
26
28
|
}
|
|
27
29
|
return response;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix-run/session-middleware",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Middleware for managing sessions with cookie-based storage",
|
|
5
5
|
"author": "Michael Jackson <mjijackson@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"@types/node": "^24.6.0",
|
|
30
30
|
"@typescript/native-preview": "7.0.0-dev.20251125.1",
|
|
31
31
|
"@remix-run/cookie": "0.5.1",
|
|
32
|
-
"@remix-run/headers": "0.19.0",
|
|
33
32
|
"@remix-run/session": "0.4.1",
|
|
34
|
-
"@remix-run/fetch-router": "0.
|
|
33
|
+
"@remix-run/fetch-router": "0.17.0",
|
|
34
|
+
"@remix-run/headers": "0.19.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@remix-run/cookie": "^0.5.1",
|
|
38
|
-
"@remix-run/
|
|
39
|
-
"@remix-run/
|
|
38
|
+
"@remix-run/fetch-router": "^0.17.0",
|
|
39
|
+
"@remix-run/session": "^0.4.1"
|
|
40
40
|
},
|
|
41
41
|
"keywords": [
|
|
42
42
|
"fetch",
|
package/src/lib/session.ts
CHANGED
|
@@ -32,6 +32,8 @@ export function session(sessionCookie: Cookie, sessionStorage: SessionStorage):
|
|
|
32
32
|
|
|
33
33
|
let setCookieValue = await sessionStorage.save(session)
|
|
34
34
|
if (setCookieValue != null) {
|
|
35
|
+
// make sure the response is mutable
|
|
36
|
+
response = new Response(response.body, response)
|
|
35
37
|
response.headers.append('Set-Cookie', await sessionCookie.serialize(setCookieValue))
|
|
36
38
|
}
|
|
37
39
|
|