import { supabase } from "@/lib/supabase";
import AdminDashboard from "./AdminDashboard";
import { cookies } from "next/headers";
import { jwtVerify } from "jose";
const SECRET_KEY = process.env.JWT_SECRET || "fallback_secret_key_for_development";
export const dynamic = 'force-dynamic';
export default async function AdminPage() {
// Check if Supabase is configured
const isDummy = (process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://dummy.supabase.co') === 'https://dummy.supabase.co';
let settingsRows = null, projectRows = null, certRows = null, articleRows = null, techStackRows = null;
if (!isDummy) {
const resSettings = await supabase.from('settings').select('*').eq('id', 1).single();
settingsRows = resSettings.data;
const resProj = await supabase.from('projects').select('*').order('id', { ascending: false });
projectRows = resProj.data;
const resCert = await supabase.from('certifications').select('*').order('id', { ascending: false });
certRows = resCert.data;
const resArt = await supabase.from('articles').select('*').order('id', { ascending: false });
articleRows = resArt.data;
const resTech = await supabase.from('techstack').select('*').order('id', { ascending: true });
techStackRows = resTech.data;
}
// Extract username from token
const cookieStore = await cookies();
const token = cookieStore.get('admin_token')?.value;
let username = "Admin";
if (token) {
try {
const secret = new TextEncoder().encode(SECRET_KEY);
const { payload } = await jwtVerify(token, secret);
username = payload.username as string;
} catch (e) {
console.error(e);
}
}
return (
<>
>
);
}