Fix sync auth, add cron script, update env.example

This commit is contained in:
2026-06-11 16:11:38 -03:00
parent 208bc52af7
commit 4ba290004c
4 changed files with 17 additions and 6 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ export default function AdminPage() {
<button
onClick={async () => {
setSyncing(true)
await fetch(`/api/admin/sync?secret=${process.env.NEXT_PUBLIC_SYNC_SECRET ?? ''}`, { method: 'POST' })
await fetch('/api/admin/sync', { method: 'POST' })
setSyncing(false)
}}
className="bg-blue-600 text-white text-xs font-bold px-3 py-1.5 rounded-full disabled:opacity-60"
+6 -1
View File
@@ -29,8 +29,13 @@ export async function POST(req: Request) {
const { searchParams } = new URL(req.url)
const secret = searchParams.get('secret')
// Acepta secret (para cron) o sesión de admin (para el panel)
if (secret !== process.env.ADMIN_SYNC_SECRET) {
return NextResponse.json({ error: 'No autorizado' }, { status: 401 })
const { getSession } = await import('@/lib/auth')
const session = await getSession()
if (!session || session.role !== 'ADMIN') {
return NextResponse.json({ error: 'No autorizado' }, { status: 401 })
}
}
const apiUrl = process.env.RESULTS_API_URL