antes de alterar login
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user