@objectstack/plugin-auth 9.5.0 → 9.6.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/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1169,12 +1169,13 @@ var AuthManager = class {
|
|
|
1169
1169
|
return false;
|
|
1170
1170
|
}
|
|
1171
1171
|
};
|
|
1172
|
-
const
|
|
1172
|
+
const platformAdmin = await isPlatformAdmin();
|
|
1173
|
+
const promote = platformAdmin || await isActiveOrgAdmin();
|
|
1173
1174
|
const storedRole = typeof user.role === "string" ? user.role : "";
|
|
1174
1175
|
const roles = storedRole.split(",").map((s) => s.trim()).filter(Boolean);
|
|
1175
1176
|
if (promote && !roles.includes("admin")) roles.push("admin");
|
|
1176
|
-
if (!promote) return { user: { ...user, roles }, session };
|
|
1177
|
-
return { user: { ...user, role: "admin", roles }, session };
|
|
1177
|
+
if (!promote) return { user: { ...user, roles, isPlatformAdmin: platformAdmin }, session };
|
|
1178
|
+
return { user: { ...user, role: "admin", roles, isPlatformAdmin: platformAdmin }, session };
|
|
1178
1179
|
}));
|
|
1179
1180
|
}
|
|
1180
1181
|
return plugins;
|
|
@@ -1322,6 +1323,14 @@ var AuthManager = class {
|
|
|
1322
1323
|
* @returns Web standard Response object
|
|
1323
1324
|
*/
|
|
1324
1325
|
async handleRequest(request) {
|
|
1326
|
+
if (process.env.NODE_ENV !== "production" && !request.headers.get("origin") && !request.headers.get("referer")) {
|
|
1327
|
+
try {
|
|
1328
|
+
const headers = new Headers(request.headers);
|
|
1329
|
+
headers.set("origin", new URL(request.url).origin);
|
|
1330
|
+
request = new Request(request, { headers });
|
|
1331
|
+
} catch {
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1325
1334
|
const auth = await this.getOrCreateAuth();
|
|
1326
1335
|
const { runWithRequestState } = await import("@better-auth/core/context");
|
|
1327
1336
|
const response = await runWithRequestState(/* @__PURE__ */ new WeakMap(), () => auth.handler(request));
|