antes de alterar login

This commit is contained in:
2026-05-26 16:40:01 +01:00
parent ef265ceeef
commit 3aa6e5468d
12 changed files with 316 additions and 92 deletions

View File

@@ -11,6 +11,7 @@ export default function AuthGuard({ children }: { children: React.ReactNode }) {
useEffect(() => {
if (!loading) {
// If user is not authenticated and not on a public page, redirect to login
if (!user && !pathname.startsWith("/login") && !pathname.startsWith("/register")) {
router.push("/login");
}
@@ -25,8 +26,8 @@ export default function AuthGuard({ children }: { children: React.ReactNode }) {
);
}
// Se não estiver logado e não estiver numa rota pública, não renderiza nada
// (o useEffect vai redirecionar)
// If not authenticated and not on a public page, don't render children
// (the useEffect will redirect)
if (!user && !pathname.startsWith("/login") && !pathname.startsWith("/register")) {
return null;
}

View File

@@ -20,12 +20,17 @@ export function NotificationMonitor() {
// Primeiro, marcamos todas as reservas existentes como "vistas"
// para não disparar notificações para o passado
const loadExisting = async () => {
const snapshot = await get(reservasRef);
if (snapshot.exists()) {
const data = snapshot.val();
Object.keys(data).forEach(id => seenReservas.current.add(id));
try {
const snapshot = await get(reservasRef);
if (snapshot.exists()) {
const data = snapshot.val();
Object.keys(data).forEach(id => seenReservas.current.add(id));
}
} catch (error) {
console.error("[NotificationMonitor] Error loading existing reservas:", error);
} finally {
isInitialLoad.current = false;
}
isInitialLoad.current = false;
};
loadExisting();
@@ -40,9 +45,13 @@ export function NotificationMonitor() {
// Se ainda estivermos no load inicial (do get), ignoramos o toast
if (isInitialLoad.current) return;
const data = snapshot.val();
if (data.restauranteEmail === user.email && data.estado === "Pendente") {
toast(`Nova reserva recebida de ${data.clienteEmail}!`, "info");
try {
const data = snapshot.val();
if (data?.restauranteEmail === user.email && data?.estado === "Pendente") {
toast(`Nova reserva recebida de ${data?.clienteEmail || "cliente"}!`, "info");
}
} catch (error) {
console.error("[NotificationMonitor] Error processing new reserva:", error);
}
});