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
+4 -4
View File
@@ -6,9 +6,9 @@ POSTGRES_DB=prode_db
# JWT - CAMBIAR en producción
JWT_SECRET=un_secret_muy_largo_y_seguro_aqui
# URL del sitio externo de resultados (se configura cuando esté disponible)
RESULTS_API_URL=
RESULTS_API_KEY=
# API de resultados (football-data.org)
RESULTS_API_URL=https://api.football-data.org/v4/competitions/WC/matches
RESULTS_API_KEY=tu_token_de_football_data_org_aqui
# Secret para proteger el endpoint de sync
# Secret para proteger el endpoint de sync (cron)
ADMIN_SYNC_SECRET=sync_secret_cambialo
+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"
+5
View File
@@ -29,9 +29,14 @@ 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) {
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
const apiKey = process.env.RESULTS_API_KEY
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
# Cron: */5 * * * * /ruta/a/sync-cron.sh >> /var/log/prode-sync.log 2>&1
curl -s -X POST "https://prode.beldo.duckdns.org/api/admin/sync?secret=${ADMIN_SYNC_SECRET}" \
-o /dev/null -w "%{http_code}" \
&& echo " [$(date '+%Y-%m-%d %H:%M')] sync ok" \
|| echo " [$(date '+%Y-%m-%d %H:%M')] sync error"