aaspai-authx 0.0.7 → 0.0.9
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/express/index.cjs +43 -27
- package/dist/express/index.cjs.map +1 -1
- package/dist/express/index.js +46 -28
- package/dist/express/index.js.map +1 -1
- package/dist/index.cjs +69 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -54
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +43 -27
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +46 -28
- package/dist/nest/index.js.map +1 -1
- package/package.json +2 -2
package/dist/nest/index.cjs
CHANGED
|
@@ -40,6 +40,24 @@ var import_crypto = require("crypto");
|
|
|
40
40
|
var import_express = __toESM(require("express"), 1);
|
|
41
41
|
var import_jsonwebtoken4 = __toESM(require("jsonwebtoken"), 1);
|
|
42
42
|
|
|
43
|
+
// src/core/utils.ts
|
|
44
|
+
function baseProjectCookieOptionsFrom(cookie) {
|
|
45
|
+
const base = {
|
|
46
|
+
secure: cookie.secure ?? false,
|
|
47
|
+
sameSite: cookie.sameSite ?? "lax",
|
|
48
|
+
path: cookie.path ?? "/",
|
|
49
|
+
maxAge: cookie.maxAgeMs
|
|
50
|
+
};
|
|
51
|
+
if (cookie.domain) base.domain = cookie.domain;
|
|
52
|
+
return base;
|
|
53
|
+
}
|
|
54
|
+
function hasAnyRole(session, roles) {
|
|
55
|
+
if (!session || !session.roles || !Array.isArray(roles) || roles.length === 0) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return roles.some((role) => session.roles.includes(role));
|
|
59
|
+
}
|
|
60
|
+
|
|
43
61
|
// src/config/loadConfig.ts
|
|
44
62
|
function loadConfig() {
|
|
45
63
|
return {
|
|
@@ -617,6 +635,16 @@ function createAuthRouter(options = {}) {
|
|
|
617
635
|
const r = (0, import_express.Router)();
|
|
618
636
|
const email = new EmailService();
|
|
619
637
|
const authAdmin = new AuthAdminService();
|
|
638
|
+
const isProdEnv = process.env.NODE_ENV === "production";
|
|
639
|
+
const cookieConfig = {
|
|
640
|
+
sameSite: options.cookie?.sameSite ?? (isProdEnv ? "none" : "lax"),
|
|
641
|
+
// default if not provided
|
|
642
|
+
secure: options.cookie?.secure ?? isProdEnv,
|
|
643
|
+
// default: secure in prod
|
|
644
|
+
domain: options.cookie?.domain ?? void 0,
|
|
645
|
+
path: options.cookie?.path ?? "/",
|
|
646
|
+
maxAgeMs: options.cookie?.maxAgeMs ?? 24 * 60 * 60 * 1e3
|
|
647
|
+
};
|
|
620
648
|
r.use(import_express.default.json());
|
|
621
649
|
r.use(import_express.default.urlencoded({ extended: true }));
|
|
622
650
|
r.get(
|
|
@@ -647,10 +675,10 @@ function createAuthRouter(options = {}) {
|
|
|
647
675
|
});
|
|
648
676
|
}
|
|
649
677
|
const tokens = generateTokens(user);
|
|
650
|
-
setAuthCookies(res, tokens);
|
|
678
|
+
setAuthCookies(res, tokens, cookieConfig);
|
|
651
679
|
if (user.projectId) {
|
|
652
680
|
res.cookie(options.projectCookieName || "projectId", user.projectId, {
|
|
653
|
-
...
|
|
681
|
+
...baseProjectCookieOptionsFrom(cookieConfig),
|
|
654
682
|
httpOnly: true
|
|
655
683
|
});
|
|
656
684
|
}
|
|
@@ -982,26 +1010,22 @@ function createAuthRouter(options = {}) {
|
|
|
982
1010
|
});
|
|
983
1011
|
return r;
|
|
984
1012
|
}
|
|
985
|
-
function setAuthCookies(res, tokens) {
|
|
1013
|
+
function setAuthCookies(res, tokens, cookie) {
|
|
1014
|
+
const base = {
|
|
1015
|
+
httpOnly: true,
|
|
1016
|
+
secure: cookie.secure ?? false,
|
|
1017
|
+
sameSite: cookie.sameSite ?? "lax",
|
|
1018
|
+
path: cookie.path ?? "/",
|
|
1019
|
+
maxAge: cookie.maxAgeMs
|
|
1020
|
+
};
|
|
1021
|
+
if (cookie.domain) {
|
|
1022
|
+
base.domain = cookie.domain;
|
|
1023
|
+
}
|
|
986
1024
|
if (tokens?.access_token) {
|
|
987
|
-
res.cookie("access_token", tokens.access_token,
|
|
988
|
-
httpOnly: true,
|
|
989
|
-
secure: false,
|
|
990
|
-
sameSite: "lax",
|
|
991
|
-
maxAge: 24 * 60 * 60 * 1e3,
|
|
992
|
-
// 24 hours
|
|
993
|
-
path: "/"
|
|
994
|
-
});
|
|
1025
|
+
res.cookie("access_token", tokens.access_token, base);
|
|
995
1026
|
}
|
|
996
1027
|
if (tokens?.refresh_token) {
|
|
997
|
-
res.cookie("refresh_token", tokens.refresh_token,
|
|
998
|
-
httpOnly: true,
|
|
999
|
-
secure: false,
|
|
1000
|
-
sameSite: "lax",
|
|
1001
|
-
maxAge: 24 * 60 * 60 * 1e3,
|
|
1002
|
-
// 24 hours
|
|
1003
|
-
path: "/"
|
|
1004
|
-
});
|
|
1028
|
+
res.cookie("refresh_token", tokens.refresh_token, base);
|
|
1005
1029
|
}
|
|
1006
1030
|
}
|
|
1007
1031
|
function toUserResponse(user) {
|
|
@@ -1210,14 +1234,6 @@ var import_bcryptjs2 = __toESM(require("bcryptjs"), 1);
|
|
|
1210
1234
|
var import_crypto3 = require("crypto");
|
|
1211
1235
|
var import_express5 = __toESM(require("express"), 1);
|
|
1212
1236
|
|
|
1213
|
-
// src/core/utils.ts
|
|
1214
|
-
function hasAnyRole(session, roles) {
|
|
1215
|
-
if (!session || !session.roles || !Array.isArray(roles) || roles.length === 0) {
|
|
1216
|
-
return false;
|
|
1217
|
-
}
|
|
1218
|
-
return roles.some((role) => session.roles.includes(role));
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
1237
|
// src/middlewares/requireRole.ts
|
|
1222
1238
|
function requireRole(...roles) {
|
|
1223
1239
|
return (req, res, next) => {
|