feat(visibility): service_settings 기반 서비스 숨김 가드 + 레거시 서비스 시드
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
29
lib/service-visibility.ts
Normal file
29
lib/service-visibility.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { cookies } from 'next/headers';
|
||||
import { createAdminClient } from '@/lib/supabase/admin';
|
||||
import { verifyAdminTokenNode } from '@/lib/admin-auth';
|
||||
|
||||
/** 숨김 가능 서비스 id (service_settings.id와 일치) */
|
||||
export type HideableService = 'saju' | 'music' | 'gyeol' | 'packages' | 'lotto';
|
||||
|
||||
/**
|
||||
* 서비스 노출 여부. admin_token 세션이면 항상 true.
|
||||
* service_settings 조회 실패(테이블 미생성 등) 시 안전하게 숨김(false).
|
||||
*/
|
||||
export async function isServiceVisible(id: HideableService): Promise<boolean> {
|
||||
const cookieStore = await cookies();
|
||||
const token = cookieStore.get('admin_token')?.value;
|
||||
if (token && verifyAdminTokenNode(token)) return true;
|
||||
|
||||
try {
|
||||
const supabase = createAdminClient();
|
||||
const { data, error } = await supabase
|
||||
.from('service_settings')
|
||||
.select('is_active')
|
||||
.eq('id', id)
|
||||
.maybeSingle();
|
||||
if (error || !data) return false;
|
||||
return data.is_active === true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user