
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
- Function Cannot be deleted
I think this shouldn't happen!
- CORS Issue | DID NOT FIND ANYTHING ON DO...
Hello There, I get the Error ```Access to fetch at 'https://fra.cloud.appwrite.io/v1/account' from origin 'http://localhost:5173' has been blocked by CORS poli...
- Database not found
Even though I can clearly access and update fields in my DB through the console, when my updating through the Android SDK it throws this error { "message": ...
