feat(convex): add internal url and remote access fixes

This commit is contained in:
Esdras Renan 2025-11-11 16:06:11 -03:00
parent feb31d48c1
commit da46fa448b
17 changed files with 73 additions and 92 deletions

View file

@ -2,9 +2,9 @@ import { NextResponse } from "next/server"
import { ConvexHttpClient } from "convex/browser"
import { api } from "@/convex/_generated/api"
import type { Id } from "@/convex/_generated/dataModel"
import { env } from "@/lib/env"
import { assertAuthenticatedSession } from "@/lib/auth-server"
import { DEFAULT_TENANT_ID } from "@/lib/constants"
import { requireConvexUrl } from "@/server/convex-client"
export const runtime = "nodejs"
@ -42,11 +42,6 @@ export async function GET(request: Request) {
return NextResponse.json({ items: [] }, { status: 401 })
}
const convexUrl = env.NEXT_PUBLIC_CONVEX_URL
if (!convexUrl) {
return NextResponse.json({ items: [] }, { status: 500 })
}
const normalizedRole = normalizeRole(session.user.role)
const isAgentOrAdmin = normalizedRole === "admin" || normalizedRole === "agent"
const canLinkOwnTickets = normalizedRole === "collaborator"
@ -59,7 +54,7 @@ export async function GET(request: Request) {
const rawQuery = url.searchParams.get("q") ?? ""
const query = rawQuery.trim()
const client = new ConvexHttpClient(convexUrl)
const client = new ConvexHttpClient(requireConvexUrl())
// Garantir que o usuário exista no Convex para obter viewerId
let viewerId: string | null = null