fix: ensure convex client fallback url
This commit is contained in:
parent
36fe4a7943
commit
3565500e9c
3 changed files with 10 additions and 11 deletions
|
|
@ -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>;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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";
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue