@remix-run/session-middleware 0.1.0 → 0.1.2

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 CHANGED
@@ -13,7 +13,7 @@ npm install @remix-run/session-middleware
13
13
  ```ts
14
14
  import { createRouter } from '@remix-run/fetch-router'
15
15
  import { createCookie } from '@remix-run/cookie'
16
- import { createCookieStorage } from '@remix-run/session/cookie-storage'
16
+ import { createCookieSessionStorage } from '@remix-run/session/cookie-storage'
17
17
  import { session } from '@remix-run/session-middleware'
18
18
 
19
19
  let sessionCookie = createCookie('__session', {
@@ -23,7 +23,7 @@ let sessionCookie = createCookie('__session', {
23
23
  sameSite: 'lax',
24
24
  })
25
25
 
26
- let sessionStorage = createCookieStorage()
26
+ let sessionStorage = createCookieSessionStorage()
27
27
 
28
28
  let router = createRouter({
29
29
  middleware: [session(sessionCookie, sessionStorage)],
@@ -49,21 +49,22 @@ A basic login/logout flow could look like this:
49
49
 
50
50
  ```ts
51
51
  import * as res from '@remix-run/fetch-router/response-helpers'
52
- import { html } from '@remix-run/html-template'
53
52
 
54
53
  router.get('/login', ({ session }) => {
55
54
  let error = session.get('error')
56
- return res.html(
57
- html` <div>
58
- <h1>Login</h1>
59
- ${typeof error === 'string' ? <div class="error">${error}</div> : null}
60
- <form method="POST" action="/login">
61
- <input type="text" name="username" placeholder="Username" />
62
- <input type="password" name="password" placeholder="Password" />
63
- <button type="submit">Login</button>
64
- </form>
65
- </div>`,
66
- )
55
+ return res.html(`
56
+ <html>
57
+ <body>
58
+ <h1>Login</h1>
59
+ ${typeof error === 'string' ? <div class="error">${error}</div> : null}
60
+ <form method="POST" action="/login">
61
+ <input type="text" name="username" placeholder="Username" />
62
+ <input type="password" name="password" placeholder="Password" />
63
+ <button type="submit">Login</button>
64
+ </form>
65
+ </body>
66
+ </html>
67
+ `)
67
68
  })
68
69
 
69
70
  router.post('/login', ({ session, formData }) => {
@@ -76,8 +77,8 @@ router.post('/login', ({ session, formData }) => {
76
77
  return res.redirect('/login')
77
78
  }
78
79
 
79
- session.set('userId', user.id)
80
80
  session.regenerateId()
81
+ session.set('userId', user.id)
81
82
 
82
83
  return res.redirect('/dashboard')
83
84
  })
@@ -1,11 +1,12 @@
1
1
  import type { Cookie } from '@remix-run/cookie';
2
- import type { SessionStorage } from '@remix-run/session';
3
2
  import type { Middleware } from '@remix-run/fetch-router';
3
+ import type { SessionStorage } from '@remix-run/session';
4
4
  /**
5
5
  * Middleware that manages `context.session` based on the session cookie.
6
- * @param cookie The session cookie to use
7
- * @param storage The storage backend for session data
6
+ *
7
+ * @param sessionCookie The session cookie to use
8
+ * @param sessionStorage The storage backend for session data
8
9
  * @returns The session middleware
9
10
  */
10
- export declare function session(cookie: Cookie, storage: SessionStorage): Middleware;
11
+ export declare function session(sessionCookie: Cookie, sessionStorage: SessionStorage): Middleware;
11
12
  //# sourceMappingURL=session.d.ts.map
@@ -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,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEzD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,UAAU,CA4B3E"}
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,CA4BzF"}
@@ -1,27 +1,28 @@
1
1
  /**
2
2
  * Middleware that manages `context.session` based on the session cookie.
3
- * @param cookie The session cookie to use
4
- * @param storage The storage backend for session data
3
+ *
4
+ * @param sessionCookie The session cookie to use
5
+ * @param sessionStorage The storage backend for session data
5
6
  * @returns The session middleware
6
7
  */
7
- export function session(cookie, storage) {
8
- if (!cookie.signed) {
8
+ export function session(sessionCookie, sessionStorage) {
9
+ if (!sessionCookie.signed) {
9
10
  throw new Error('Session cookie must be signed');
10
11
  }
11
12
  return async (context, next) => {
12
13
  if (context.sessionStarted) {
13
14
  throw new Error('Existing session found, refusing to overwrite');
14
15
  }
15
- let cookieValue = await cookie.parse(context.headers.get('Cookie'));
16
- let session = await storage.read(cookieValue);
16
+ let cookieValue = await sessionCookie.parse(context.headers.get('Cookie'));
17
+ let session = await sessionStorage.read(cookieValue);
17
18
  context.session = session;
18
19
  let response = await next();
19
20
  if (session !== context.session) {
20
21
  throw new Error('Cannot save session that was initialized by another middleware/handler');
21
22
  }
22
- let setCookieValue = await storage.save(session);
23
+ let setCookieValue = await sessionStorage.save(session);
23
24
  if (setCookieValue != null) {
24
- response.headers.set('Set-Cookie', await cookie.serialize(setCookieValue));
25
+ response.headers.append('Set-Cookie', await sessionCookie.serialize(setCookieValue));
25
26
  }
26
27
  return response;
27
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/session-middleware",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Middleware for managing sessions with cookie-based storage",
5
5
  "author": "Michael Jackson <mjijackson@gmail.com>",
6
6
  "license": "MIT",
@@ -27,16 +27,16 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^24.6.0",
30
- "typescript": "^5.9.3",
31
- "@remix-run/cookie": "0.4.1",
32
- "@remix-run/headers": "0.17.0",
33
- "@remix-run/fetch-router": "0.9.0",
34
- "@remix-run/session": "0.2.1"
30
+ "@typescript/native-preview": "7.0.0-dev.20251125.1",
31
+ "@remix-run/cookie": "0.5.1",
32
+ "@remix-run/headers": "0.19.0",
33
+ "@remix-run/fetch-router": "0.15.1",
34
+ "@remix-run/session": "0.4.1"
35
35
  },
36
- "peerDependencies": {
37
- "@remix-run/cookie": "^0.4.1",
38
- "@remix-run/fetch-router": "^0.9.0",
39
- "@remix-run/session": "^0.2.1"
36
+ "dependencies": {
37
+ "@remix-run/cookie": "^0.5.1",
38
+ "@remix-run/fetch-router": "^0.15.1",
39
+ "@remix-run/session": "^0.4.1"
40
40
  },
41
41
  "keywords": [
42
42
  "fetch",
@@ -47,9 +47,9 @@
47
47
  "session-management"
48
48
  ],
49
49
  "scripts": {
50
- "build": "tsc -p tsconfig.build.json",
50
+ "build": "tsgo -p tsconfig.build.json",
51
51
  "clean": "git clean -fdX",
52
- "test": "node --disable-warning=ExperimentalWarning --test './src/**/*.test.ts'",
53
- "typecheck": "tsc --noEmit"
52
+ "test": "node --disable-warning=ExperimentalWarning --test",
53
+ "typecheck": "tsgo --noEmit"
54
54
  }
55
55
  }
package/src/index.ts CHANGED
@@ -1,2 +1 @@
1
1
  export { session } from './lib/session.ts'
2
-
@@ -1,16 +1,16 @@
1
1
  import type { Cookie } from '@remix-run/cookie'
2
- import type { SessionStorage } from '@remix-run/session'
3
-
4
2
  import type { Middleware } from '@remix-run/fetch-router'
3
+ import type { SessionStorage } from '@remix-run/session'
5
4
 
6
5
  /**
7
6
  * Middleware that manages `context.session` based on the session cookie.
8
- * @param cookie The session cookie to use
9
- * @param storage The storage backend for session data
7
+ *
8
+ * @param sessionCookie The session cookie to use
9
+ * @param sessionStorage The storage backend for session data
10
10
  * @returns The session middleware
11
11
  */
12
- export function session(cookie: Cookie, storage: SessionStorage): Middleware {
13
- if (!cookie.signed) {
12
+ export function session(sessionCookie: Cookie, sessionStorage: SessionStorage): Middleware {
13
+ if (!sessionCookie.signed) {
14
14
  throw new Error('Session cookie must be signed')
15
15
  }
16
16
 
@@ -19,8 +19,8 @@ export function session(cookie: Cookie, storage: SessionStorage): Middleware {
19
19
  throw new Error('Existing session found, refusing to overwrite')
20
20
  }
21
21
 
22
- let cookieValue = await cookie.parse(context.headers.get('Cookie'))
23
- let session = await storage.read(cookieValue)
22
+ let cookieValue = await sessionCookie.parse(context.headers.get('Cookie'))
23
+ let session = await sessionStorage.read(cookieValue)
24
24
 
25
25
  context.session = session
26
26
 
@@ -30,12 +30,11 @@ export function session(cookie: Cookie, storage: SessionStorage): Middleware {
30
30
  throw new Error('Cannot save session that was initialized by another middleware/handler')
31
31
  }
32
32
 
33
- let setCookieValue = await storage.save(session)
33
+ let setCookieValue = await sessionStorage.save(session)
34
34
  if (setCookieValue != null) {
35
- response.headers.set('Set-Cookie', await cookie.serialize(setCookieValue))
35
+ response.headers.append('Set-Cookie', await sessionCookie.serialize(setCookieValue))
36
36
  }
37
37
 
38
38
  return response
39
39
  }
40
40
  }
41
-