unjwt 0.5.33 → 0.5.35

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.
@@ -44,10 +44,12 @@ interface SessionHooksJWE<T extends Record<string, any> = SessionClaims, MaxAge
44
44
  }) => void | Promise<void>;
45
45
  onUpdate?: (args: {
46
46
  session: SessionJWE<T, MaxAge>;
47
+ oldSession: SessionJWE<T, MaxAge>;
47
48
  event: H3Event;
48
49
  config: SessionConfigJWE<T, MaxAge>;
49
50
  }) => void | Promise<void>;
50
51
  onClear?: (args: {
52
+ session: SessionJWE<T, MaxAge> | undefined;
51
53
  event: H3Event;
52
54
  config: Partial<SessionConfigJWE<T, MaxAge>>;
53
55
  }) => void | Promise<void>;
@@ -163,10 +165,12 @@ interface SessionHooksJWS<T extends Record<string, any> = SessionClaims, MaxAge
163
165
  }) => void | Promise<void>;
164
166
  onUpdate?: (args: {
165
167
  session: SessionJWS<T, MaxAge>;
168
+ oldSession: SessionJWS<T, MaxAge>;
166
169
  event: H3Event;
167
170
  config: SessionConfigJWS<T, MaxAge>;
168
171
  }) => void | Promise<void>;
169
172
  onClear?: (args: {
173
+ session: SessionJWS<T, MaxAge> | undefined;
170
174
  event: H3Event;
171
175
  config: Partial<SessionConfigJWS<T, MaxAge>>;
172
176
  }) => void | Promise<void>;
@@ -189,10 +189,12 @@ async function updateJWESession(event, config, update) {
189
189
  update = update(session.data);
190
190
  }
191
191
  if (update) {
192
+ const oldSession = { ...session, data: { ...session.data } };
192
193
  Object.assign(session.data, update);
193
194
  await config.hooks?.onUpdate?.({
194
- event,
195
195
  session,
196
+ oldSession,
197
+ event,
196
198
  config
197
199
  });
198
200
  }
@@ -285,6 +287,10 @@ async function unsealJWESession(event, config, sealed) {
285
287
  }
286
288
  async function clearJWESession(event, config) {
287
289
  const sessionName = config.name || DEFAULT_NAME$1;
290
+ let session = event.context.sessions?.[sessionName];
291
+ if (session && session[kGetSessionPromise$1]) {
292
+ session = await session[kGetSessionPromise$1];
293
+ }
288
294
  if (event.context.sessions?.[sessionName]) {
289
295
  delete event.context.sessions[sessionName];
290
296
  }
@@ -295,6 +301,7 @@ async function clearJWESession(event, config) {
295
301
  maxAge: void 0
296
302
  });
297
303
  await config.hooks?.onClear?.({
304
+ session,
298
305
  event,
299
306
  config
300
307
  });
@@ -531,10 +538,12 @@ async function updateJWSSession(event, config, update) {
531
538
  update = update(session.data);
532
539
  }
533
540
  if (update) {
541
+ const oldSession = { ...session, data: { ...session.data } };
534
542
  Object.assign(session.data, update);
535
543
  await config.hooks?.onUpdate?.({
536
- event,
537
544
  session,
545
+ oldSession,
546
+ event,
538
547
  config
539
548
  });
540
549
  }
@@ -620,6 +629,10 @@ async function verifyJWSSession(event, config, token) {
620
629
  }
621
630
  async function clearJWSSession(event, config) {
622
631
  const sessionName = config.name || DEFAULT_NAME;
632
+ let session = event.context.sessions?.[sessionName];
633
+ if (session && session[kGetSessionPromise]) {
634
+ session = await session[kGetSessionPromise];
635
+ }
623
636
  if (event.context.sessions?.[sessionName]) {
624
637
  delete event.context.sessions[sessionName];
625
638
  }
@@ -630,6 +643,7 @@ async function clearJWSSession(event, config) {
630
643
  maxAge: void 0
631
644
  });
632
645
  await config.hooks?.onClear?.({
646
+ session,
633
647
  event,
634
648
  config
635
649
  });
@@ -38,10 +38,12 @@ interface SessionHooksJWE<T extends Record<string, any> = SessionClaims, MaxAge
38
38
  }) => void | Promise<void>;
39
39
  onUpdate?: (args: {
40
40
  session: SessionJWE<T, MaxAge>;
41
+ oldSession: SessionJWE<T, MaxAge>;
41
42
  event: HTTPEvent;
42
43
  config: SessionConfigJWE<T, MaxAge>;
43
44
  }) => void | Promise<void>;
44
45
  onClear?: (args: {
46
+ session: SessionJWE<T, MaxAge> | undefined;
45
47
  event: HTTPEvent;
46
48
  config: Partial<SessionConfigJWE<T, MaxAge>>;
47
49
  }) => void | Promise<void>;
@@ -128,10 +130,12 @@ interface SessionHooksJWS<T extends Record<string, any> = SessionClaims, MaxAge
128
130
  }) => void | Promise<void>;
129
131
  onUpdate?: (args: {
130
132
  session: SessionJWS<T, MaxAge>;
133
+ oldSession: SessionJWS<T, MaxAge>;
131
134
  event: HTTPEvent;
132
135
  config: SessionConfigJWS<T, MaxAge>;
133
136
  }) => void | Promise<void>;
134
137
  onClear?: (args: {
138
+ session: SessionJWS<T, MaxAge> | undefined;
135
139
  event: HTTPEvent;
136
140
  config: Partial<SessionConfigJWS<T, MaxAge>>;
137
141
  }) => void | Promise<void>;
@@ -149,10 +149,12 @@ async function updateJWESession(event, config, update) {
149
149
  update = update(session.data);
150
150
  }
151
151
  if (update) {
152
+ const oldSession = { ...session, data: { ...session.data } };
152
153
  Object.assign(session.data, update);
153
154
  await config.hooks?.onUpdate?.({
154
- event,
155
+ oldSession,
155
156
  session,
157
+ event,
156
158
  config
157
159
  });
158
160
  }
@@ -243,6 +245,10 @@ async function unsealJWESession(event, config, sealed) {
243
245
  async function clearJWESession(event, config) {
244
246
  const context = getEventContext(event);
245
247
  const sessionName = config.name || DEFAULT_NAME$1;
248
+ let session = context.sessions?.[sessionName];
249
+ if (session && session[kGetSessionPromise$1]) {
250
+ session = await session[kGetSessionPromise$1];
251
+ }
246
252
  if (context.sessions?.[sessionName]) {
247
253
  delete context.sessions[sessionName];
248
254
  }
@@ -254,6 +260,7 @@ async function clearJWESession(event, config) {
254
260
  maxAge: void 0
255
261
  });
256
262
  await config.hooks?.onClear?.({
263
+ session,
257
264
  event,
258
265
  config
259
266
  });
@@ -455,10 +462,12 @@ async function updateJWSSession(event, config, update) {
455
462
  update = update(session.data);
456
463
  }
457
464
  if (update) {
465
+ const oldSession = { ...session, data: { ...session.data } };
458
466
  Object.assign(session.data, update);
459
467
  await config.hooks?.onUpdate?.({
460
- event,
461
468
  session,
469
+ oldSession,
470
+ event,
462
471
  config
463
472
  });
464
473
  }
@@ -545,6 +554,10 @@ async function verifyJWSSession(event, config, token) {
545
554
  async function clearJWSSession(event, config) {
546
555
  const context = getEventContext(event);
547
556
  const sessionName = config.name || DEFAULT_NAME;
557
+ let session = context.sessions?.[sessionName];
558
+ if (session && session[kGetSessionPromise]) {
559
+ session = await session[kGetSessionPromise];
560
+ }
548
561
  if (context.sessions?.[sessionName]) {
549
562
  delete context.sessions[sessionName];
550
563
  }
@@ -556,6 +569,7 @@ async function clearJWSSession(event, config) {
556
569
  maxAge: void 0
557
570
  });
558
571
  await config.hooks?.onClear?.({
572
+ session,
559
573
  event,
560
574
  config
561
575
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unjwt",
3
- "version": "0.5.33",
3
+ "version": "0.5.35",
4
4
  "description": "Low-level JWT utilities",
5
5
  "repository": "sandros94/unjwt",
6
6
  "license": "MIT",