first commit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
'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 }
|
||||
}
|
||||
Reference in New Issue
Block a user