elseware-nodejs 1.5.0 → 1.5.2
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/index.cjs +28 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +28 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5307,8 +5307,8 @@ var JWTService = class {
|
|
|
5307
5307
|
constructor(options) {
|
|
5308
5308
|
this.accessSecret = options.accessSecret;
|
|
5309
5309
|
this.refreshSecret = options.refreshSecret;
|
|
5310
|
-
this.accessExpires = options.accessExpires
|
|
5311
|
-
this.refreshExpires = options.refreshExpires
|
|
5310
|
+
this.accessExpires = this.parseExpires(options.accessExpires, "15m");
|
|
5311
|
+
this.refreshExpires = this.parseExpires(options.refreshExpires, "30d");
|
|
5312
5312
|
this.nodeEnv = options.nodeEnv || "development";
|
|
5313
5313
|
this.refreshCookieName = options.refreshCookieName || "refreshJwt";
|
|
5314
5314
|
}
|
|
@@ -5348,14 +5348,18 @@ var JWTService = class {
|
|
|
5348
5348
|
// Token Extraction
|
|
5349
5349
|
// ---------------------------------
|
|
5350
5350
|
extractToken(req) {
|
|
5351
|
+
let token = null;
|
|
5351
5352
|
if (req.headers.authorization?.startsWith("Bearer ")) {
|
|
5352
|
-
|
|
5353
|
+
token = req.headers.authorization.split(" ")[1];
|
|
5354
|
+
return token ? this.normalizeToken(token) : null;
|
|
5353
5355
|
}
|
|
5354
5356
|
if (req.cookies?.[this.refreshCookieName]) {
|
|
5355
|
-
|
|
5357
|
+
token = req.cookies[this.refreshCookieName];
|
|
5358
|
+
return token ? this.normalizeToken(token) : null;
|
|
5356
5359
|
}
|
|
5357
5360
|
if (req.cookies?.jwt) {
|
|
5358
|
-
|
|
5361
|
+
token = req.cookies.jwt;
|
|
5362
|
+
return token ? this.normalizeToken(token) : null;
|
|
5359
5363
|
}
|
|
5360
5364
|
return null;
|
|
5361
5365
|
}
|
|
@@ -5388,6 +5392,25 @@ var JWTService = class {
|
|
|
5388
5392
|
this.setRefreshTokenCookie(res, refreshToken);
|
|
5389
5393
|
return accessToken;
|
|
5390
5394
|
}
|
|
5395
|
+
// ---------------------------------
|
|
5396
|
+
// Internal Helpers
|
|
5397
|
+
// ---------------------------------
|
|
5398
|
+
normalizeToken(token) {
|
|
5399
|
+
token = token.trim();
|
|
5400
|
+
if (token.startsWith('"') && token.endsWith('"')) {
|
|
5401
|
+
try {
|
|
5402
|
+
return JSON.parse(token);
|
|
5403
|
+
} catch {
|
|
5404
|
+
return token.slice(1, -1);
|
|
5405
|
+
}
|
|
5406
|
+
}
|
|
5407
|
+
return token;
|
|
5408
|
+
}
|
|
5409
|
+
parseExpires(value, fallback) {
|
|
5410
|
+
if (!value) return fallback;
|
|
5411
|
+
if (typeof value === "number") return value;
|
|
5412
|
+
return value;
|
|
5413
|
+
}
|
|
5391
5414
|
};
|
|
5392
5415
|
|
|
5393
5416
|
// src/utils/time.ts
|