23 lines
629 B
TypeScript
23 lines
629 B
TypeScript
'use server'
|
|
|
|
import { saveCategories, type Category } from '@/data/menu'
|
|
import { revalidatePath } from 'next/cache'
|
|
import { cookies } from 'next/headers'
|
|
|
|
async function checkAuth() {
|
|
const cookieStore = await cookies()
|
|
const session = cookieStore.get('admin_session')?.value
|
|
if (!session || session !== (process.env.ADMIN_SECRET || 'secret')) {
|
|
throw new Error('Unauthorized')
|
|
}
|
|
}
|
|
|
|
export async function saveEntireMenu(categories: Category[]) {
|
|
await checkAuth()
|
|
await saveCategories(categories)
|
|
// Revalidate both language paths
|
|
revalidatePath('/tr')
|
|
revalidatePath('/en')
|
|
return { success: true }
|
|
}
|