36 lines
964 B
JavaScript
36 lines
964 B
JavaScript
import { supabase } from '../../lib/supabase';
|
|
|
|
export default async function handler(req, res) {
|
|
if (req.method !== 'DELETE') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
const isAuthenticated = req.cookies.isAuthenticated === 'true';
|
|
if (!isAuthenticated) {
|
|
return res.status(401).json({ error: 'Unauthorized' });
|
|
}
|
|
|
|
const { id } = req.body;
|
|
|
|
if (!id) {
|
|
return res.status(400).json({ error: 'ID ist erforderlich' });
|
|
}
|
|
|
|
try {
|
|
const { error } = await supabase
|
|
.from('blog_entries')
|
|
.delete()
|
|
.eq('id', id);
|
|
|
|
if (error) {
|
|
console.error('Supabase Lösch-Fehler:', error);
|
|
return res.status(500).json({ error: 'Fehler beim Löschen des Beitrags' });
|
|
}
|
|
|
|
return res.status(200).json({ message: 'Beitrag erfolgreich gelöscht' });
|
|
} catch (error) {
|
|
console.error('Server-Fehler:', error);
|
|
return res.status(500).json({ error: 'Interner Server-Fehler' });
|
|
}
|
|
}
|