Skip to content
Sites Hackathon is live / Aug 29 - Sep 12
Back

Realtime is not working!!

  • 0
  • Realtime
  • Cloud
Saimon
2 Sep, 2025, 10:25

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**

TypeScript
    "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(); }, []); } ```

TL;DR
Realtime feature not working due to session setup issues. The problem might be related to SSR conflicting with realtime functions. Solution: Avoid using SSR for realtime applications unless necessary for SEO.
D5
2 Sep, 2025, 10:40

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.

D5
2 Sep, 2025, 10:41

Also, cookies token != JWT

D5
2 Sep, 2025, 10:43

To create the session client side you need to use javascript sessionClient.setSession(session);

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more