
It shows Session is not valid
. I am using SSR login.
If if set table permission User(Read)
then realtime can not show update. But if I set table permission Any(Read)
then realtime can show update.
** Login function**
"use server";
try {
const { account } = await createAdminClient();
const session = await account.createEmailPasswordSession(email, password);
const isVerified = await auth.isVerified(session.secret);
if (!isVerified) {
await auth.sendVerifyEmail(session.secret);
await auth.logout(session.secret);
return {
error: "Email not verified! A new link has been sent to your email.",
};
}
(await cookies()).set("session", session.secret, {
httpOnly: true,
sameSite: "strict",
secure: true,
expires: new Date(session.expire),
path: "/",
});
const jwt = await auth.setJWT(session.secret);
(await cookies()).set("jwt", jwt, {
httpOnly: false,
sameSite: "strict",
secure: true,
maxAge: 60 * 15,
path: "/",
});
return {
success: true,
};
} catch (error) {
console.log("Error in login......", error);
return { error: error.message };
}
},```
> **Client Side code**
"use client"; import {useEffect} from "react"; import Cookies from "js-cookie"; import { client, account } from "@/lib/appwriteWeb";
export default function ToDoList() { useEffect(() => { const getUser = async () => { const jwt = Cookies.get("jwt"); client.setJWT(jwt); const user = await account.get(); console.log(user); client.subscribe("databases.db1.tables.todolist.rows", (event) => { console.log("Realtime is working ", event); }); }; getUser(); }, []); } ```

If if set table permission User(Read) then realtime can not show update. But if I set table permission Any(Read) then realtime can show update. That probably means realtime is not getting the session properly. I think that the issue is that SSR is conflicting. I strongly recommend not using SSR for realtime applications unless you need SEO for those pages as it's not supported server sided.

Also, cookies token != JWT

To create the session client side you need to use javascript
sessionClient.setSession(session);
Recommended threads
- WebSocket reconnecting issues – Realtime...
Hello! I am experiencing a problem with the Realtime API. My frontend is constantly reconnecting to the WebSocket server, and as a result Realtime is not worki...
- Migration issues
Hey, quick question — I’m currently running a project on an Appwrite Pro account, but I recently got access to the GitHub Student Pack. Is there a way to migrat...
- updateDocument() throws "document_alread...
Hi guys, im using server sdk to update appwrite attribute value which relationship type. But facing "document_already_exists", may i know why?
