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

@ -6,7 +6,6 @@ import { ConvexHttpClient } from "convex/browser"
import { api } from "@/convex/_generated/api"
import { DEFAULT_TENANT_ID } from "@/lib/constants"
import { env } from "@/lib/env"
import { prisma } from "@/lib/prisma"
import {
computeInviteStatus,
@ -14,6 +13,7 @@ import {
normalizeRoleOption,
type NormalizedInvite,
} from "@/server/invite-utils"
import { requireConvexUrl } from "@/server/convex-client"
type AcceptInvitePayload = {
name?: string
@ -25,9 +25,8 @@ function validatePassword(password: string) {
}
async function syncInvite(invite: NormalizedInvite) {
const convexUrl = env.NEXT_PUBLIC_CONVEX_URL
if (!convexUrl) return
const client = new ConvexHttpClient(convexUrl)
const url = requireConvexUrl()
const client = new ConvexHttpClient(url)
await client.mutation(api.invites.sync, {
tenantId: invite.tenantId,
inviteId: invite.id,
@ -178,20 +177,17 @@ export async function POST(request: Request, context: { params: Promise<{ token:
const normalized = normalizeInvite({ ...updatedInvite, events: [...invite.events, event] }, now)
await syncInvite(normalized)
const convexUrl = env.NEXT_PUBLIC_CONVEX_URL
if (convexUrl) {
try {
const convex = new ConvexHttpClient(convexUrl)
await convex.mutation(api.users.ensureUser, {
tenantId,
email: invite.email,
name,
avatarUrl: undefined,
role: role.toUpperCase(),
})
} catch (error) {
console.warn("Falha ao sincronizar usuário no Convex", error)
}
try {
const convex = new ConvexHttpClient(requireConvexUrl())
await convex.mutation(api.users.ensureUser, {
tenantId,
email: invite.email,
name,
avatarUrl: undefined,
role: role.toUpperCase(),
})
} catch (error) {
console.warn("Falha ao sincronizar usuário no Convex", error)
}
return NextResponse.json({ success: true })