@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.mjs
CHANGED
|
@@ -1102,12 +1102,13 @@ var AuthManager = class {
|
|
|
1102
1102
|
return false;
|
|
1103
1103
|
}
|
|
1104
1104
|
};
|
|
1105
|
-
const
|
|
1105
|
+
const platformAdmin = await isPlatformAdmin();
|
|
1106
|
+
const promote = platformAdmin || await isActiveOrgAdmin();
|
|
1106
1107
|
const storedRole = typeof user.role === "string" ? user.role : "";
|
|
1107
1108
|
const roles = storedRole.split(",").map((s) => s.trim()).filter(Boolean);
|
|
1108
1109
|
if (promote && !roles.includes("admin")) roles.push("admin");
|
|
1109
|
-
if (!promote) return { user: { ...user, roles }, session };
|
|
1110
|
-
return { user: { ...user, role: "admin", roles }, session };
|
|
1110
|
+
if (!promote) return { user: { ...user, roles, isPlatformAdmin: platformAdmin }, session };
|
|
1111
|
+
return { user: { ...user, role: "admin", roles, isPlatformAdmin: platformAdmin }, session };
|
|
1111
1112
|
}));
|
|
1112
1113
|
}
|
|
1113
1114
|
return plugins;
|
|
@@ -1255,6 +1256,14 @@ var AuthManager = class {
|
|
|
1255
1256
|
* @returns Web standard Response object
|
|
1256
1257
|
*/
|
|
1257
1258
|
async handleRequest(request) {
|
|
1259
|
+
if (process.env.NODE_ENV !== "production" && !request.headers.get("origin") && !request.headers.get("referer")) {
|
|
1260
|
+
try {
|
|
1261
|
+
const headers = new Headers(request.headers);
|
|
1262
|
+
headers.set("origin", new URL(request.url).origin);
|
|
1263
|
+
request = new Request(request, { headers });
|
|
1264
|
+
} catch {
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1258
1267
|
const auth = await this.getOrCreateAuth();
|
|
1259
1268
|
const { runWithRequestState } = await import("@better-auth/core/context");
|
|
1260
1269
|
const response = await runWithRequestState(/* @__PURE__ */ new WeakMap(), () => auth.handler(request));
|