diff --git a/web/scripts/debug-convex.mjs b/web/scripts/debug-convex.mjs new file mode 100644 index 0000000..258df55 --- /dev/null +++ b/web/scripts/debug-convex.mjs @@ -0,0 +1,46 @@ +import { ConvexHttpClient } from "convex/browser"; + +const url = process.env.NEXT_PUBLIC_CONVEX_URL; + +if (!url) { + console.error("Missing NEXT_PUBLIC_CONVEX_URL"); + process.exit(1); +} + +const client = new ConvexHttpClient(url); + +const tenantId = process.argv[2] ?? "tenant-atlas"; + +const ensureAdmin = await client.mutation("users:ensureUser", { + tenantId, + email: "admin@sistema.dev", + name: "Administrador", + role: "ADMIN", +}); + +console.log("Ensured admin user:", ensureAdmin); + +const agents = await client.query("users:listAgents", { tenantId }); +console.log("Agents:", agents); + +const viewerId = ensureAdmin?._id ?? agents[0]?._id; + +if (!viewerId) { + console.error("Unable to determine viewer id"); + process.exit(1); +} + +const tickets = await client.query("tickets:list", { + tenantId, + viewerId, + limit: 10, +}); + +console.log("Tickets:", tickets); + +const dashboard = await client.query("reports:dashboardOverview", { + tenantId, + viewerId, +}); + +console.log("Dashboard:", dashboard); diff --git a/web/scripts/seed-auth.mjs b/web/scripts/seed-auth.mjs index 18c0fbe..7e76634 100644 --- a/web/scripts/seed-auth.mjs +++ b/web/scripts/seed-auth.mjs @@ -1,6 +1,7 @@ -import { PrismaClient } from "@prisma/client" +import pkg from "@prisma/client" import { hashPassword } from "better-auth/crypto" +const { PrismaClient } = pkg const prisma = new PrismaClient() const email = process.env.SEED_USER_EMAIL ?? "admin@sistema.dev" diff --git a/web/src/app/login/page.tsx b/web/src/app/login/page.tsx index a86f4d6..3dbb6c8 100644 --- a/web/src/app/login/page.tsx +++ b/web/src/app/login/page.tsx @@ -1,6 +1,6 @@ "use client" -import { useEffect } from "react" +import { useEffect, useState } from "react" import Link from "next/link" import { useRouter, useSearchParams } from "next/navigation" import { GalleryVerticalEnd } from "lucide-react" @@ -19,6 +19,7 @@ export default function LoginPage() { const searchParams = useSearchParams() const { data: session, isPending } = useSession() const callbackUrl = searchParams?.get("callbackUrl") ?? undefined + const [isHydrated, setIsHydrated] = useState(false) useEffect(() => { if (!session?.user) return @@ -26,6 +27,12 @@ export default function LoginPage() { router.replace(destination) }, [callbackUrl, router, session?.user]) + useEffect(() => { + setIsHydrated(true) + }, []) + + const shouldDisable = !isHydrated || isPending + return (