2026-03-23 18:09:59 +02:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { currentUserAtom } from "@/atoms/user/user-query.atoms";
|
|
|
|
|
import { queries } from "@/zero/queries";
|
|
|
|
|
import { schema } from "@/zero/schema";
|
|
|
|
|
import { ZeroProvider as ZeroReactProvider } from "@rocicorp/zero/react";
|
|
|
|
|
import { useAtomValue } from "jotai";
|
|
|
|
|
|
|
|
|
|
const cacheURL = process.env.NEXT_PUBLIC_ZERO_CACHE_URL || "http://localhost:4848";
|
|
|
|
|
|
|
|
|
|
export function ZeroProvider({ children }: { children: React.ReactNode }) {
|
|
|
|
|
const { data: user } = useAtomValue(currentUserAtom);
|
2026-03-23 19:49:28 +02:00
|
|
|
|
|
|
|
|
if (!user?.id) {
|
|
|
|
|
return <>{children}</>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const userID = String(user.id);
|
|
|
|
|
const context = { userId: userID };
|
2026-03-23 18:09:59 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ZeroReactProvider {...{ userID, context, cacheURL, schema, queries }}>
|
|
|
|
|
{children}
|
|
|
|
|
</ZeroReactProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|