Rank 2: Process
"use client";
import { useEffect } from "react";
import { getSessionCookie } from "@/actions/auth";
import { createBrowserSessionClient } from "@/lib/appwrite-browser";
export default function Orders() {
useEffect(() => {
const startRealtime = async () => {
const session = await getSessionCookie();
if (!session) return;
const { client } = createBrowserSessionClient(session);
const unsubscribe = client.subscribe(
`databases.${process.env
.NEXT_PUBLIC_APPWRITE_DATABASE!}.collections.${process.env
.NEXT_PUBLIC_APPWRITE_COLLECTION_ORDERS!}.documents`,
(response) => {
console.log(response);
}
);
return () => {
unsubscribe();
};
};
startRealtime();
}, []);
return ;
}
Dev stack: Next.js
I now need to set the collections permissions to anyone who can access them in order to receive real time. I am sure that the session I passed in is correct.