@dyyz1993/codenomad 0.15.4 → 0.15.5
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/dist/auth/manager.js
CHANGED
|
@@ -128,13 +128,13 @@ function resolvePath(filePath) {
|
|
|
128
128
|
}
|
|
129
129
|
return path.resolve(filePath);
|
|
130
130
|
}
|
|
131
|
+
const DEFAULT_SESSION_MAX_AGE = 315360000; // 10 years in seconds
|
|
131
132
|
function buildSessionCookie(name, value, options) {
|
|
133
|
+
const maxAge = options?.maxAgeSeconds ?? DEFAULT_SESSION_MAX_AGE;
|
|
132
134
|
const parts = [`${name}=${encodeURIComponent(value)}`, "HttpOnly", "Path=/", "SameSite=Lax"];
|
|
133
135
|
if (options?.secure) {
|
|
134
136
|
parts.push("Secure");
|
|
135
137
|
}
|
|
136
|
-
|
|
137
|
-
parts.push(`Max-Age=${Math.max(0, Math.floor(options.maxAgeSeconds))}`);
|
|
138
|
-
}
|
|
138
|
+
parts.push(`Max-Age=${Math.max(0, Math.floor(maxAge))}`);
|
|
139
139
|
return parts.join("; ");
|
|
140
140
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import crypto from "crypto";
|
|
2
|
-
const SESSION_TTL_MS =
|
|
2
|
+
const SESSION_TTL_MS = 315360000 * 1000; // 10 years in ms
|
|
3
3
|
const CLEANUP_INTERVAL_MS = 30 * 60 * 1000;
|
|
4
4
|
export class SessionManager {
|
|
5
5
|
constructor() {
|
|
@@ -15,7 +15,14 @@ export class SessionManager {
|
|
|
15
15
|
getSession(id) {
|
|
16
16
|
if (!id)
|
|
17
17
|
return undefined;
|
|
18
|
-
|
|
18
|
+
const info = this.sessions.get(id);
|
|
19
|
+
if (!info)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (Date.now() - info.createdAt > SESSION_TTL_MS) {
|
|
22
|
+
this.sessions.delete(id);
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
return info;
|
|
19
26
|
}
|
|
20
27
|
validateSession(sessionId) {
|
|
21
28
|
const info = this.sessions.get(sessionId);
|