F-201 F-202 F-203: POS cash close report + email + PIN admin

F-201: GET /pos/reports/cash-close/:id with financial summary, sales
  by state, payments breakdown, items sold. Extended /pos/sessions/:id.

F-202: Cash close email sent on session close to smtpReportEmail
  (best-effort). smtpReportEmail field added to admin SMTP settings.

F-203: Admin POS terminal config: selfpayMode, closeSessionRequiresPin,
  closeSessionPin (4-6 digits) with dedicated settings section.
This commit is contained in:
chattie
2026-08-23 09:24:37 +02:00
parent 4b3a506166
commit 18a518e58b
100 changed files with 1704 additions and 284 deletions

View File

@@ -0,0 +1,16 @@
import { NextRequest, NextResponse } from 'next/server';
const API = process.env.NEXT_PUBLIC_API_URL ?? 'http://127.0.0.1:3000';
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const token = searchParams.get('token');
if (!token) {
return NextResponse.json({ error: { message: 'Token requerido' } }, { status: 400 });
}
const res = await fetch(`${API}/auth/confirm?token=${encodeURIComponent(token)}`, {
credentials: 'include',
});
const data = await res.json();
return NextResponse.json(data, { status: res.status });
}

View File

@@ -0,0 +1,74 @@
'use client';
import { useEffect, useState } from 'react';
import { useRouter, useSearchParams } from 'next/navigation';
import Link from 'next/link';
export default function ConfirmPage() {
const router = useRouter();
const params = useSearchParams();
const token = params.get('token');
const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading');
const [message, setMessage] = useState('Confirmando tu email…');
useEffect(() => {
if (!token) {
setStatus('error');
setMessage('Falta el token de confirmación.');
return;
}
fetch(`/api/auth/confirm?token=${encodeURIComponent(token)}`)
.then(async (r) => {
const data = await r.json();
if (r.ok) {
setStatus('success');
setMessage(data.message ?? 'Email confirmado.');
setTimeout(() => router.push('/auth/login'), 3000);
} else {
setStatus('error');
setMessage(data.error?.message ?? 'Token inválido o ya confirmado.');
}
})
.catch(() => {
setStatus('error');
setMessage('Error de conexión.');
});
}, [token, router]);
return (
<div className="max-w-md mx-auto px-4 py-16">
<div className="bg-white border border-gray-200 rounded-2xl p-8 shadow-sm text-center">
{status === 'loading' && (
<div className="mb-4">
<svg className="animate-spin mx-auto" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="#70ad47" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
</div>
)}
{status === 'success' && (
<div className="mb-4 flex justify-center">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#22c55e" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M5 13l4 4L19 7"/>
</svg>
</div>
)}
{status === 'error' && (
<div className="mb-4 flex justify-center">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#ef4444" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12"/>
</svg>
</div>
)}
<h1 className="text-2xl font-bold text-gray-900 mb-4" style={{ fontFamily: 'var(--font-heading)' }}>
{status === 'success' ? '¡Email confirmado!' : status === 'error' ? 'Error' : 'Confirmando…'}
</h1>
<p className="text-gray-600 mb-6">{message}</p>
{status === 'success' && (
<p className="text-sm text-gray-400 mb-4">Redirigiendo al login</p>
)}
<Link href="/auth/login" className="text-[#70ad47] hover:underline text-sm">
Ir a iniciar sesión
</Link>
</div>
</div>
);
}

View File

@@ -12,6 +12,7 @@ export default function RegisterPage() {
const [confirm, setConfirm] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const [done, setDone] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
@@ -24,12 +25,36 @@ export default function RegisterPage() {
const result = await register(email, password);
setLoading(false);
if (result.ok) {
router.push('/');
setDone(true);
} else {
setError(result.error || 'Error al crear cuenta');
}
};
if (done) {
return (
<div className="max-w-md mx-auto px-4 py-16">
<div className="bg-white border border-gray-200 rounded-2xl p-8 shadow-sm text-center">
<div className="mb-4 flex justify-center">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#22c55e" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
</svg>
</div>
<h1 className="text-2xl font-bold text-gray-900 mb-4" style={{ fontFamily: 'var(--font-heading)' }}>
¡Revisa tu correo!
</h1>
<p className="text-gray-600 mb-6">
Hemos enviado un enlace de confirmación a <strong>{email}</strong>.<br/>
Haz clic en el enlace para activar tu cuenta.
</p>
<p className="text-sm text-gray-400">
¿No lo recibiste? <Link href="/auth/register" className="text-[#70ad47] hover:underline">Inténtalo de nuevo</Link>
</p>
</div>
</div>
);
}
return (
<div className="max-w-md mx-auto px-4 py-16">
<div className="bg-white border border-gray-200 rounded-2xl p-8 shadow-sm">

View File

@@ -45,8 +45,8 @@ function addressToForm(addr: SavedAddress) {
phone: '',
address: addr.street,
city: addr.city,
postalCode: addr.postalCode,
country: addr.country,
postalCode: addr.postalCode ?? '',
country: addr.country ?? '',
};
}

View File

@@ -21,11 +21,14 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
// FIX-198: must send credentials so the session cookie is included.
// FIX-198: /auth/me returns {id,email,role} when authenticated, {user:null} when not.
useEffect(() => {
fetch('/api/auth/me')
fetch('/api/auth/me', { credentials: 'include' })
.then((r) => r.json())
.then((data) => {
setUser(data.user ?? null);
// When authenticated: { id, email, role }. When not: { user: null }.
setUser(data.user ?? (data.id ? data : null));
})
.catch(() => setUser(null))
.finally(() => setLoading(false));