@wtfalch/auth 0.13.0 → 0.14.0

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.
@@ -248,11 +248,30 @@ export function namespaceSessions(deps) {
248
248
  .catch(() => { });
249
249
  return stillValid ? leased : null;
250
250
  }
251
- const committed = await store().advance(key, generation, {
252
- payload: await seal(key, fresh),
253
- expiresAt: now() + options().sessionMaxAge,
254
- leaseUntil: null,
255
- });
251
+ let committed;
252
+ try {
253
+ committed = await store().advance(key, generation, {
254
+ payload: await seal(key, fresh),
255
+ expiresAt: now() + options().sessionMaxAge,
256
+ leaseUntil: null,
257
+ });
258
+ }
259
+ catch (error) {
260
+ // The commit itself threw (a store outage): the lease is still held.
261
+ // Best-effort release it, as the still-valid path above already does,
262
+ // so the session does not stay locked out for up to LEASE_SECONDS, and
263
+ // revoke a rotated refresh token that was never stored.
264
+ await store()
265
+ .advance(key, generation, {
266
+ payload: record.payload,
267
+ expiresAt: record.expiresAt,
268
+ leaseUntil: null,
269
+ })
270
+ .catch(() => { });
271
+ if (fresh.refreshToken !== tokens.rt)
272
+ revokeToken(fresh.refreshToken);
273
+ throw error;
274
+ }
256
275
  if (!committed) {
257
276
  // Revoked while we asked, or our lease ran out and another request took
258
277
  // over. These tokens are kept nowhere, so they are not left live.
@@ -351,11 +370,31 @@ export function namespaceSessions(deps) {
351
370
  // does for the same case.
352
371
  throw error;
353
372
  }
354
- const committed = await store().advance(key, generation, {
355
- payload: await seal(key, fresh),
356
- expiresAt: now() + options().sessionMaxAge,
357
- leaseUntil: null,
358
- });
373
+ let committed;
374
+ try {
375
+ committed = await store().advance(key, generation, {
376
+ payload: await seal(key, fresh),
377
+ expiresAt: now() + options().sessionMaxAge,
378
+ leaseUntil: null,
379
+ });
380
+ }
381
+ catch (error) {
382
+ // The commit itself threw (a store outage): the lease is still held.
383
+ // Best-effort release it, as the still-valid path in `refreshLeased`
384
+ // does, so the session does not stay locked out for up to
385
+ // LEASE_SECONDS, and revoke a rotated refresh token that was never
386
+ // stored.
387
+ await store()
388
+ .advance(key, generation, {
389
+ payload: record.payload,
390
+ expiresAt: record.expiresAt,
391
+ leaseUntil: null,
392
+ })
393
+ .catch(() => { });
394
+ if (fresh.refreshToken !== tokens.rt)
395
+ revokeToken(fresh.refreshToken);
396
+ throw error;
397
+ }
359
398
  if (!committed) {
360
399
  // Revoked while the grant was in flight, or the lease ran out and
361
400
  // another request took over. The fresh tokens are kept nowhere, so
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wtfalch/auth",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Sign in against auth.wtfalch.dev: a server session for a Next.js app, and a browser client with silent single sign-on across subdomains.",
5
5
  "repository": {
6
6
  "type": "git",