unjwt 0.5.35 → 0.5.37
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/adapters/h3.mjs +24 -16
- package/dist/adapters/h3v2.mjs +24 -16
- package/package.json +1 -1
package/dist/adapters/h3.mjs
CHANGED
|
@@ -120,9 +120,6 @@ async function getJWESession(event, config) {
|
|
|
120
120
|
"Cannot initialize a new session. Use `useSession(event)` within the main handler."
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
|
-
session.id = config.generateId?.() ?? crypto.randomUUID();
|
|
124
|
-
session.createdAt = config.jwe?.encryptOptions?.currentDate?.getTime() ?? Date.now();
|
|
125
|
-
session.expiresAt = config.maxAge === void 0 ? void 0 : session.createdAt + computeExpiresInSeconds(config.maxAge) * 1e3;
|
|
126
123
|
await updateJWESession(event, config);
|
|
127
124
|
}
|
|
128
125
|
await config.hooks?.onRead?.({
|
|
@@ -198,6 +195,13 @@ async function updateJWESession(event, config, update) {
|
|
|
198
195
|
config
|
|
199
196
|
});
|
|
200
197
|
}
|
|
198
|
+
const now = config.jwe?.encryptOptions?.currentDate?.getTime() ?? Date.now();
|
|
199
|
+
const createdAt = now - now % 1e3;
|
|
200
|
+
Object.assign(session, {
|
|
201
|
+
id: config.generateId?.() || crypto.randomUUID(),
|
|
202
|
+
createdAt,
|
|
203
|
+
expiresAt: config.maxAge === void 0 ? void 0 : createdAt + computeExpiresInSeconds(config.maxAge) * 1e3
|
|
204
|
+
});
|
|
201
205
|
if (config.cookie !== false) {
|
|
202
206
|
const sealed = await sealJWESession(event, config);
|
|
203
207
|
setCookie(event, sessionName, sealed, {
|
|
@@ -215,15 +219,15 @@ async function sealJWESession(event, config) {
|
|
|
215
219
|
const key = getEncryptKey(config.key || config.secret);
|
|
216
220
|
const sessionName = config.name || DEFAULT_NAME$1;
|
|
217
221
|
const session = event.context.sessions?.[sessionName] || await getJWESession(event, config);
|
|
218
|
-
const
|
|
219
|
-
const
|
|
222
|
+
const iat = Math.floor(session.createdAt / 1e3);
|
|
223
|
+
const exp = session.expiresAt ? Math.floor(session.expiresAt / 1e3) : void 0;
|
|
220
224
|
const payload = {
|
|
221
225
|
...session.data,
|
|
222
226
|
jti: session.id,
|
|
223
|
-
iat
|
|
227
|
+
iat
|
|
224
228
|
};
|
|
225
|
-
if (
|
|
226
|
-
payload.exp =
|
|
229
|
+
if (exp) {
|
|
230
|
+
payload.exp = exp;
|
|
227
231
|
}
|
|
228
232
|
let typ = void 0;
|
|
229
233
|
if (config.jwe?.encryptOptions?.protectedHeader?.typ && typeof config.jwe.encryptOptions.protectedHeader.typ === "string" && config.jwe.encryptOptions.protectedHeader.typ.toLowerCase().includes("jwt")) {
|
|
@@ -469,9 +473,6 @@ async function getJWSSession(event, config) {
|
|
|
469
473
|
"Cannot initialize a new session outside main handler. Use `useJWSSession(event)` properly."
|
|
470
474
|
);
|
|
471
475
|
}
|
|
472
|
-
session.id = config.generateId?.() ?? crypto.randomUUID();
|
|
473
|
-
session.createdAt = config.jws?.signOptions?.currentDate?.getTime() ?? Date.now();
|
|
474
|
-
session.expiresAt = config.maxAge === void 0 ? void 0 : session.createdAt + computeExpiresInSeconds(config.maxAge) * 1e3;
|
|
475
476
|
await updateJWSSession(event, config);
|
|
476
477
|
}
|
|
477
478
|
await config.hooks?.onRead?.({
|
|
@@ -547,6 +548,13 @@ async function updateJWSSession(event, config, update) {
|
|
|
547
548
|
config
|
|
548
549
|
});
|
|
549
550
|
}
|
|
551
|
+
const now = config.jws?.signOptions?.currentDate?.getTime() ?? Date.now();
|
|
552
|
+
const createdAt = now - now % 1e3;
|
|
553
|
+
Object.assign(session, {
|
|
554
|
+
id: config.generateId?.() || crypto.randomUUID(),
|
|
555
|
+
createdAt,
|
|
556
|
+
expiresAt: config.maxAge === void 0 ? void 0 : createdAt + computeExpiresInSeconds(config.maxAge) * 1e3
|
|
557
|
+
});
|
|
550
558
|
if (config.cookie !== false) {
|
|
551
559
|
const token = await signJWSSession(event, config);
|
|
552
560
|
setCookie(event, sessionName, token, {
|
|
@@ -563,15 +571,15 @@ async function signJWSSession(event, config) {
|
|
|
563
571
|
const key = getSignKey(config.key);
|
|
564
572
|
const sessionName = config.name || DEFAULT_NAME;
|
|
565
573
|
const session = event.context.sessions?.[sessionName] || await getJWSSession(event, config);
|
|
566
|
-
const
|
|
567
|
-
const
|
|
574
|
+
const iat = Math.floor(session.createdAt / 1e3);
|
|
575
|
+
const exp = session.expiresAt ? Math.floor(session.expiresAt / 1e3) : void 0;
|
|
568
576
|
const payload = {
|
|
569
577
|
...session.data,
|
|
570
578
|
jti: session.id,
|
|
571
|
-
iat
|
|
579
|
+
iat
|
|
572
580
|
};
|
|
573
|
-
if (
|
|
574
|
-
payload.exp =
|
|
581
|
+
if (exp) {
|
|
582
|
+
payload.exp = exp;
|
|
575
583
|
}
|
|
576
584
|
let typ = void 0;
|
|
577
585
|
if (config.jws?.signOptions?.protectedHeader?.typ && typeof config.jws.signOptions.protectedHeader.typ === "string" && config.jws.signOptions.protectedHeader.typ.toLowerCase().includes("jwt")) {
|
package/dist/adapters/h3v2.mjs
CHANGED
|
@@ -108,9 +108,6 @@ async function getJWESession(event, config) {
|
|
|
108
108
|
await promise;
|
|
109
109
|
}
|
|
110
110
|
if (!session.id) {
|
|
111
|
-
session.id = config.generateId?.() ?? crypto.randomUUID();
|
|
112
|
-
session.createdAt = config.jwe?.encryptOptions?.currentDate?.getTime() ?? Date.now();
|
|
113
|
-
session.expiresAt = config.maxAge === void 0 ? void 0 : session.createdAt + computeExpiresInSeconds(config.maxAge) * 1e3;
|
|
114
111
|
await updateJWESession(event, config);
|
|
115
112
|
}
|
|
116
113
|
await config.hooks?.onRead?.({
|
|
@@ -158,6 +155,13 @@ async function updateJWESession(event, config, update) {
|
|
|
158
155
|
config
|
|
159
156
|
});
|
|
160
157
|
}
|
|
158
|
+
const now = config.jwe?.encryptOptions?.currentDate?.getTime() ?? Date.now();
|
|
159
|
+
const createdAt = now - now % 1e3;
|
|
160
|
+
Object.assign(session, {
|
|
161
|
+
id: config.generateId?.() || crypto.randomUUID(),
|
|
162
|
+
createdAt,
|
|
163
|
+
expiresAt: config.maxAge === void 0 ? void 0 : createdAt + computeExpiresInSeconds(config.maxAge) * 1e3
|
|
164
|
+
});
|
|
161
165
|
if (config.cookie !== false && hasWritableResponse$1(event)) {
|
|
162
166
|
const sealed = await sealJWESession(event, config);
|
|
163
167
|
setChunkedCookie(event, sessionName, sealed, {
|
|
@@ -175,15 +179,15 @@ async function sealJWESession(event, config) {
|
|
|
175
179
|
const sessionName = config.name || DEFAULT_NAME$1;
|
|
176
180
|
const context = getEventContext(event);
|
|
177
181
|
const session = context.sessions?.[sessionName] || await getJWESession(event, config);
|
|
178
|
-
const
|
|
179
|
-
const
|
|
182
|
+
const iat = Math.floor(session.createdAt / 1e3);
|
|
183
|
+
const exp = session.expiresAt ? Math.floor(session.expiresAt / 1e3) : void 0;
|
|
180
184
|
const payload = {
|
|
181
185
|
...session.data,
|
|
182
186
|
jti: session.id,
|
|
183
|
-
iat
|
|
187
|
+
iat
|
|
184
188
|
};
|
|
185
|
-
if (
|
|
186
|
-
payload.exp =
|
|
189
|
+
if (exp) {
|
|
190
|
+
payload.exp = exp;
|
|
187
191
|
}
|
|
188
192
|
let typ = void 0;
|
|
189
193
|
if (config.jwe?.encryptOptions?.protectedHeader?.typ && typeof config.jwe.encryptOptions.protectedHeader.typ === "string" && config.jwe.encryptOptions.protectedHeader.typ.toLowerCase().includes("jwt")) {
|
|
@@ -421,9 +425,6 @@ async function getJWSSession(event, config) {
|
|
|
421
425
|
await promise;
|
|
422
426
|
}
|
|
423
427
|
if (!session.id) {
|
|
424
|
-
session.id = config.generateId?.() ?? crypto.randomUUID();
|
|
425
|
-
session.createdAt = config.jws?.signOptions?.currentDate?.getTime() ?? Date.now();
|
|
426
|
-
session.expiresAt = config.maxAge === void 0 ? void 0 : session.createdAt + computeExpiresInSeconds(config.maxAge) * 1e3;
|
|
427
428
|
await updateJWSSession(event, config);
|
|
428
429
|
}
|
|
429
430
|
await config.hooks?.onRead?.({
|
|
@@ -471,6 +472,13 @@ async function updateJWSSession(event, config, update) {
|
|
|
471
472
|
config
|
|
472
473
|
});
|
|
473
474
|
}
|
|
475
|
+
const now = config.jws?.signOptions?.currentDate?.getTime() ?? Date.now();
|
|
476
|
+
const createdAt = now - now % 1e3;
|
|
477
|
+
Object.assign(session, {
|
|
478
|
+
id: config.generateId?.() || crypto.randomUUID(),
|
|
479
|
+
createdAt,
|
|
480
|
+
expiresAt: config.maxAge === void 0 ? void 0 : createdAt + computeExpiresInSeconds(config.maxAge) * 1e3
|
|
481
|
+
});
|
|
474
482
|
if (config.cookie !== false && hasWritableResponse(event)) {
|
|
475
483
|
const token = await signJWSSession(event, config);
|
|
476
484
|
setChunkedCookie(event, sessionName, token, {
|
|
@@ -488,15 +496,15 @@ async function signJWSSession(event, config) {
|
|
|
488
496
|
const sessionName = config.name || DEFAULT_NAME;
|
|
489
497
|
const context = getEventContext(event);
|
|
490
498
|
const session = context.sessions?.[sessionName] || await getJWSSession(event, config);
|
|
491
|
-
const
|
|
492
|
-
const
|
|
499
|
+
const iat = Math.floor(session.createdAt / 1e3);
|
|
500
|
+
const exp = session.expiresAt ? Math.floor(session.expiresAt / 1e3) : void 0;
|
|
493
501
|
const payload = {
|
|
494
502
|
...session.data,
|
|
495
503
|
jti: session.id,
|
|
496
|
-
iat
|
|
504
|
+
iat
|
|
497
505
|
};
|
|
498
|
-
if (
|
|
499
|
-
payload.exp =
|
|
506
|
+
if (exp) {
|
|
507
|
+
payload.exp = exp;
|
|
500
508
|
}
|
|
501
509
|
let typ;
|
|
502
510
|
if (config.jws?.signOptions?.protectedHeader?.typ && typeof config.jws.signOptions.protectedHeader.typ === "string" && config.jws.signOptions.protectedHeader.typ.toLowerCase().includes("jwt")) {
|