@logto/node 3.1.8 → 3.1.10

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
@@ -86,10 +86,16 @@ But the cookie size is limited, so you may need to use external storage like Red
86
86
  import { CookieStorage } from '@logto/node';
87
87
 
88
88
  class RedisSessionWrapper implements SessionWrapper {
89
+ private currentSessionId?: string;
90
+
89
91
  constructor(private readonly redis: Redis) {}
90
92
 
91
93
  async wrap(data: unknown, _key: string): Promise<string> {
92
- const sessionId = randomUUID();
94
+ // Reuse existing session ID if available, only generate new one for first-time users.
95
+ // This is important for environments where cookies cannot be updated (e.g. React Server Components),
96
+ // as the session ID in the cookie must remain stable while the data in Redis can be updated.
97
+ const sessionId = this.currentSessionId ?? randomUUID();
98
+ this.currentSessionId = sessionId;
93
99
  await this.redis.set(`logto_session_${sessionId}`, JSON.stringify(data));
94
100
  return sessionId;
95
101
  }
@@ -99,8 +105,10 @@ class RedisSessionWrapper implements SessionWrapper {
99
105
  return {};
100
106
  }
101
107
 
108
+ // Store the session ID for potential reuse in wrap()
109
+ this.currentSessionId = value;
102
110
  const data = await this.redis.get(`logto_session_${value}`);
103
- return JSON.parse(data);
111
+ return data ? JSON.parse(data) : {};
104
112
  }
105
113
  }
106
114
 
package/lib/edge/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createRequester } from '@logto/client';
2
2
  export { PersistKey } from '@logto/client';
3
3
  import LogtoNodeBaseClient from '../src/client.js';
4
- import { generateCodeChallenge, generateCodeVerifier, generateState } from './generators.js';
4
+ import { generateState, generateCodeVerifier, generateCodeChallenge } from './generators.js';
5
5
 
6
6
  // Used for edge runtime, currently only NextJS.
7
7
  class LogtoClient extends LogtoNodeBaseClient {
package/lib/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequester } from '@logto/client';
2
2
  export { LogtoClientError, LogtoError, LogtoRequestError, OidcError, PersistKey, Prompt, ReservedResource, ReservedScope, StandardLogtoClient, UserScope, buildOrganizationUrn, getOrganizationIdFromUrn, organizationUrnPrefix } from '@logto/client';
3
- import { generateCodeChallenge, generateCodeVerifier, generateState } from '../edge/generators.js';
3
+ import { generateState, generateCodeVerifier, generateCodeChallenge } from '../edge/generators.js';
4
4
  import LogtoNodeBaseClient from './client.js';
5
5
  export { unwrapSession, wrapSession } from './utils/session.js';
6
6
  export { CookieStorage } from './utils/cookie-storage.js';
@@ -1,5 +1,5 @@
1
1
  import { PromiseQueue } from './promise-queue.js';
2
- import { wrapSession, unwrapSession } from './session.js';
2
+ import { unwrapSession, wrapSession } from './session.js';
3
3
 
4
4
  /**
5
5
  * A storage that persists data in cookies with encryption.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/node",
3
- "version": "3.1.8",
3
+ "version": "3.1.10",
4
4
  "type": "module",
5
5
  "module": "./lib/src/index.js",
6
6
  "types": "./lib/src/index.d.ts",
@@ -28,9 +28,9 @@
28
28
  "directory": "packages/node"
29
29
  },
30
30
  "dependencies": {
31
- "@silverhand/essentials": "^2.9.2",
31
+ "@silverhand/essentials": "^2.9.3",
32
32
  "js-base64": "^3.7.4",
33
- "@logto/client": "^3.1.6"
33
+ "@logto/client": "^3.1.8"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@silverhand/eslint-config": "^6.0.1",