@logto/node 3.1.8 → 3.1.9
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 +10 -2
- package/package.json +3 -3
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
|
-
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/node",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.9",
|
|
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.
|
|
31
|
+
"@silverhand/essentials": "^2.9.3",
|
|
32
32
|
"js-base64": "^3.7.4",
|
|
33
|
-
"@logto/client": "^3.1.
|
|
33
|
+
"@logto/client": "^3.1.7"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@silverhand/eslint-config": "^6.0.1",
|