@dudousxd/nestjs-media-dashboard 0.8.0 → 0.9.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.
- package/dist/server/index.cjs +34 -9
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +11 -1
- package/dist/server/index.d.ts +11 -1
- package/dist/server/index.js +34 -9
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -75,6 +75,9 @@ function resolveConsoleAuth(options) {
|
|
|
75
75
|
} : {},
|
|
76
76
|
...options.login ? {
|
|
77
77
|
login: options.login
|
|
78
|
+
} : {},
|
|
79
|
+
...options.revalidate ? {
|
|
80
|
+
revalidate: options.revalidate
|
|
78
81
|
} : {}
|
|
79
82
|
};
|
|
80
83
|
}
|
|
@@ -349,14 +352,16 @@ var MediaConsoleGuard = class {
|
|
|
349
352
|
this.auth = auth;
|
|
350
353
|
this.cookiePath = cookiePath;
|
|
351
354
|
}
|
|
352
|
-
canActivate(context) {
|
|
355
|
+
async canActivate(context) {
|
|
353
356
|
if (!this.auth) return true;
|
|
354
357
|
const http = context.switchToHttp();
|
|
355
358
|
const request = http.getRequest();
|
|
356
359
|
const session = this.verifyRequestSession(request);
|
|
357
360
|
if (!session) throw new import_common.UnauthorizedException();
|
|
358
361
|
attachSession(request, session);
|
|
359
|
-
this.maybeRenew(http.getResponse(), request, session)
|
|
362
|
+
if (!await this.maybeRenew(http.getResponse(), request, session)) {
|
|
363
|
+
throw new import_common.UnauthorizedException();
|
|
364
|
+
}
|
|
360
365
|
return true;
|
|
361
366
|
}
|
|
362
367
|
verifyRequestSession(request) {
|
|
@@ -368,26 +373,46 @@ var MediaConsoleGuard = class {
|
|
|
368
373
|
});
|
|
369
374
|
}
|
|
370
375
|
/**
|
|
371
|
-
* Sliding renewal: when a valid cookie is past half its TTL, re-issue a fresh one
|
|
372
|
-
* never get logged out mid-session
|
|
376
|
+
* Sliding renewal + revalidation: when a valid cookie is past half its TTL, re-issue a fresh one
|
|
377
|
+
* so active users never get logged out mid-session — but first let the host's `revalidate` hook
|
|
378
|
+
* re-check the user, so a deactivated or demoted operator loses access instead of riding a
|
|
379
|
+
* self-renewing cookie. Returns `false` when the session was revoked (cookie already cleared).
|
|
373
380
|
*/
|
|
374
|
-
maybeRenew(response, request, session) {
|
|
375
|
-
if (!this.auth) return;
|
|
381
|
+
async maybeRenew(response, request, session) {
|
|
382
|
+
if (!this.auth) return true;
|
|
376
383
|
const now = Date.now();
|
|
377
|
-
if (now - session.iat <= this.auth.ttlMs / 2) return;
|
|
378
|
-
|
|
384
|
+
if (now - session.iat <= this.auth.ttlMs / 2) return true;
|
|
385
|
+
const user = {
|
|
379
386
|
id: session.sub,
|
|
380
387
|
...session.name !== void 0 ? {
|
|
381
388
|
name: session.name
|
|
382
389
|
} : {},
|
|
383
390
|
roles: session.roles
|
|
384
|
-
}
|
|
391
|
+
};
|
|
392
|
+
if (this.auth.revalidate) {
|
|
393
|
+
let allowed;
|
|
394
|
+
try {
|
|
395
|
+
allowed = await this.auth.revalidate(user);
|
|
396
|
+
} catch {
|
|
397
|
+
allowed = false;
|
|
398
|
+
}
|
|
399
|
+
if (!allowed) {
|
|
400
|
+
clearSessionCookie({
|
|
401
|
+
cookiePath: this.cookiePath ?? "/",
|
|
402
|
+
request,
|
|
403
|
+
response
|
|
404
|
+
});
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
issueSessionCookie(user, {
|
|
385
409
|
auth: this.auth,
|
|
386
410
|
cookiePath: this.cookiePath ?? "/",
|
|
387
411
|
request,
|
|
388
412
|
response,
|
|
389
413
|
now
|
|
390
414
|
});
|
|
415
|
+
return true;
|
|
391
416
|
}
|
|
392
417
|
};
|
|
393
418
|
MediaConsoleGuard = _ts_decorate([
|