fix: expose staging admin entry
Deploy staging to test server / deploy (push) Successful in 3m11s

Use persisted self-hosted roles and the isolated admin origin so authorized staging accounts can discover the protected admin surface.
This commit is contained in:
linmeng
2026-07-29 10:14:39 +08:00
parent f7fd3e6a60
commit 2dac8bc47b
9 changed files with 100 additions and 19 deletions
+15
View File
@@ -8,6 +8,7 @@ const migration = readFileSync(
);
const auth = readFileSync(new URL("../src/lib/admin/auth.ts", import.meta.url), "utf8");
const authPolicy = readFileSync(new URL("../src/lib/admin/auth-policy.ts", import.meta.url), "utf8");
const adminUser = readFileSync(new URL("../src/lib/supabase/admin.ts", import.meta.url), "utf8");
const codesRoute = readFileSync(new URL("../src/app/api/admin/codes/route.ts", import.meta.url), "utf8");
const codeRoute = readFileSync(new URL("../src/app/api/admin/codes/[id]/route.ts", import.meta.url), "utf8");
const providers = readFileSync(new URL("../src/lib/admin/providers.ts", import.meta.url), "utf8");
@@ -27,6 +28,20 @@ test("admin APIs use persisted Better Auth roles with admin and viewer boundarie
assert.match(codeRoute, /requireAdminSession\("write"\)/g);
});
test("self-hosted account entry checks persisted admin or viewer roles", () => {
const selfHostedBranch = adminUser.slice(
adminUser.indexOf('process.env.AUTH_PROVIDER?.trim() === "self-hosted"'),
adminUser.indexOf("if (isAdminEmail"),
);
assert.match(selfHostedBranch, /queryAdminRows/);
assert.match(selfHostedBranch, /select role from identity\.users where id = \$1 limit 1/);
assert.match(selfHostedBranch, /role === "admin" \|\| role === "viewer"/);
assert.doesNotMatch(selfHostedBranch, /isAdminEmail|ADMIN_EMAILS/);
assert.match(auth, /getIdentityAuthServices\(\)\.admin\.api/);
assert.match(auth, /authorizeAdminAccess\(user, access\)/);
});
test("readonly resources cannot be mutated through Refine access control", () => {
for (const resource of ["users", "credit-transactions", "consultations", "audit-logs"]) {
assert.match(providers, new RegExp(`"${resource}"`));