DB 기반 관리자 권한으로 전환
- ncue_user에 is_admin 추가 및 can_manage 호환 유지 - /api/auth/sync 및 관리 API를 DB is_admin 기반으로 변경 - index.html 폴백에서 관리자 이메일 하드코딩 제거 - .env로 관리자 부트스트랩(ADMIN_EMAILS) 지원 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
32
script.js
32
script.js
@@ -71,29 +71,16 @@
|
||||
"link-ncue-net",
|
||||
"dreamgirl-ncue-net",
|
||||
]);
|
||||
const DEFAULT_ADMIN_EMAILS = new Set([
|
||||
"dsyoon@ncue.net",
|
||||
"dosangyoon@gmail.com",
|
||||
"dosangyoon2@gmail.com",
|
||||
"dosangyoon3@gmail.com",
|
||||
]);
|
||||
|
||||
function getUserEmail() {
|
||||
const e = auth && auth.user && auth.user.email ? String(auth.user.email) : "";
|
||||
return e.trim().toLowerCase();
|
||||
}
|
||||
|
||||
function isAdminEmail(email) {
|
||||
const e = String(email || "").trim().toLowerCase();
|
||||
const cfg = getAuthConfig();
|
||||
const admins = Array.isArray(cfg.adminEmails) ? cfg.adminEmails : [];
|
||||
if (admins.length) return admins.includes(e);
|
||||
return DEFAULT_ADMIN_EMAILS.has(e);
|
||||
}
|
||||
|
||||
function canAccessLink(link) {
|
||||
// Admin (DB: ncue_user.is_admin) can access all links.
|
||||
if (auth && auth.authorized) return true;
|
||||
const email = getUserEmail();
|
||||
if (email && isAdminEmail(email)) return true;
|
||||
const id = String(link && link.id ? link.id : "");
|
||||
if (email) return ACCESS_USER_IDS.has(id);
|
||||
return ACCESS_ANON_IDS.has(id);
|
||||
@@ -896,15 +883,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function isManageAdminEmail(email) {
|
||||
const cfg = getAuthConfig();
|
||||
const admins = Array.isArray(cfg.adminEmails) ? cfg.adminEmails : [];
|
||||
const e = String(email || "").trim().toLowerCase();
|
||||
if (admins.length) return admins.includes(e);
|
||||
// 안전한 기본값: 설정이 비어있으면 기본 관리자만 관리 가능
|
||||
return DEFAULT_ADMIN_EMAILS.has(e);
|
||||
}
|
||||
|
||||
function updateAuthUi() {
|
||||
// 로그인 전에는 사용자 배지를 숨김(요청: "로그인 설정 필요" 영역 제거)
|
||||
if (!auth.user) {
|
||||
@@ -982,8 +960,7 @@
|
||||
auth.mode = "enabled";
|
||||
await manualHandleCallbackIfNeeded().catch(() => {});
|
||||
auth.user = await manualLoadUser();
|
||||
const email = auth.user && auth.user.email ? String(auth.user.email) : "";
|
||||
auth.authorized = Boolean(auth.user) && isManageAdminEmail(email);
|
||||
auth.authorized = false;
|
||||
auth.serverCanManage = null;
|
||||
const t = loadTokens();
|
||||
if (auth.user && t && t.id_token) {
|
||||
@@ -1037,8 +1014,7 @@
|
||||
|
||||
const isAuthed = await auth.client.isAuthenticated();
|
||||
auth.user = isAuthed ? await auth.client.getUser() : null;
|
||||
const email = auth.user && auth.user.email ? auth.user.email : "";
|
||||
auth.authorized = Boolean(auth.user) && isManageAdminEmail(email);
|
||||
auth.authorized = false;
|
||||
auth.serverCanManage = null;
|
||||
|
||||
// 로그인되었으면 서버에 사용자 upsert 및 can_manage 동기화(서버가 있을 때만)
|
||||
|
||||
Reference in New Issue
Block a user