fix: ensure convex client fallback url

This commit is contained in:
Esdras Renan 2025-11-17 16:17:16 -03:00
parent 36fe4a7943
commit 3565500e9c
3 changed files with 10 additions and 11 deletions

View file

@ -2,16 +2,14 @@
import "@/lib/toast-patch"; import "@/lib/toast-patch";
import { ConvexProvider, ConvexReactClient } from "convex/react"; import { ConvexProvider, ConvexReactClient } from "convex/react"
import { ReactNode } from "react"; import { ReactNode } from "react"
const convexUrl = process.env.NEXT_PUBLIC_CONVEX_URL; import { DEFAULT_CONVEX_URL } from "@/lib/constants"
const client = convexUrl ? new ConvexReactClient(convexUrl) : undefined; const resolvedConvexUrl = process.env.NEXT_PUBLIC_CONVEX_URL ?? DEFAULT_CONVEX_URL
const client = new ConvexReactClient(resolvedConvexUrl)
export function ConvexClientProvider({ children }: { children: ReactNode }) { export function ConvexClientProvider({ children }: { children: ReactNode }) {
if (!convexUrl) { return <ConvexProvider client={client}>{children}</ConvexProvider>
return <>{children}</>;
}
return <ConvexProvider client={client!}>{children}</ConvexProvider>;
} }

View file

@ -1,2 +1,2 @@
export const DEFAULT_TENANT_ID = "tenant-atlas"; export const DEFAULT_TENANT_ID = "tenant-atlas";
export const DEFAULT_CONVEX_URL = "https://convex.esdrasrenan.com.br";

View file

@ -1,6 +1,7 @@
import { ConvexHttpClient } from "convex/browser" import { ConvexHttpClient } from "convex/browser"
import { env } from "@/lib/env" import { env } from "@/lib/env"
import { DEFAULT_CONVEX_URL } from "@/lib/constants"
export class ConvexConfigurationError extends Error { export class ConvexConfigurationError extends Error {
constructor(message = "Convex não configurado.") { constructor(message = "Convex não configurado.") {
@ -15,8 +16,8 @@ function isServerSide() {
export function requireConvexUrl(): string { export function requireConvexUrl(): string {
const url = isServerSide() const url = isServerSide()
? env.CONVEX_INTERNAL_URL ?? env.NEXT_PUBLIC_CONVEX_URL ? env.CONVEX_INTERNAL_URL ?? env.NEXT_PUBLIC_CONVEX_URL ?? DEFAULT_CONVEX_URL
: env.NEXT_PUBLIC_CONVEX_URL : env.NEXT_PUBLIC_CONVEX_URL ?? DEFAULT_CONVEX_URL
if (!url) { if (!url) {
throw new ConvexConfigurationError() throw new ConvexConfigurationError()
} }