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
+17 -1
View File
@@ -1,5 +1,6 @@
import "server-only";
import { queryAdminRows } from "@/lib/admin/database";
import {
createAdminSupabaseClient,
isAdminEmail,
@@ -8,8 +9,23 @@ import {
export { createAdminSupabaseClient, isAdminEmail };
export async function isAdminUser(user: { id?: string; email?: string | null }) {
if (process.env.AUTH_PROVIDER?.trim() === "self-hosted") {
if (!user.id) return false;
try {
const rows = await queryAdminRows<{ role: string }>(
"select role from identity.users where id = $1 limit 1",
[user.id],
);
return rows[0]?.role
.split(",")
.map((role) => role.trim())
.some((role) => role === "admin" || role === "viewer") ?? false;
} catch {
return false;
}
}
if (isAdminEmail(user.email)) return true;
if (process.env.AUTH_PROVIDER?.trim() === "self-hosted" || !user.id) return false;
if (!user.id) return false;
try {
const admin = createAdminSupabaseClient();