#[SOLVED] Realtime feature not working

27 messages · Page 1 of 1 (latest)

cerulean fox
#

Can anyone explain why the realtime feature not working here:

const initializeAppwrite = async () => {
      // Only run in browser environment

      try {
        const { client, databases } = await createClient(sessionSecret);
        if (!client || !databases) return;

        setClient(client);
        setDatabases(databases);

        // Fetch conversations
        const response = await databases.listDocuments(
          DATABASE_ID,
          CONVERSATION_COLLECTION,
          [
            Query.or([
              Query.equal("clientId", currentUserId),
              Query.equal("freelancerId", currentUserId),
            ]),
            Query.orderDesc("$updatedAt"),
          ]
        );
/*Skipped code*/
unsubscribe = client.subscribe(
          `databases.${DATABASE_ID}.collections.${CONVERSATION_COLLECTION}.documents`,
          (response) => {
            // Handle realtime updates
            if (
              response.events.includes(
                "databases.*.collections.*.documents.*.create"
              )
            ) {
              enhanceConversation(response.payload).then((enhancedConv) => {
                setConversations((prev) => [enhancedConv, ...prev]);
              });
            }
            if (
              response.events.includes(
                "databases.*.collections.*.documents.*.update"
              )
            ) {
              console.log(response.payload);
              enhanceConversation(response.payload).then((enhancedConv) => {
                setConversations((prev) => [
                  enhancedConv,
                  ...prev.filter((conv) => conv.$id !== enhancedConv.$id),
                ]);
              });
            }
          }
        );

        setLoading(false);
        return () => {
          unsubscribe();
        };
      } catch (error) {
        setError(error.message);
        setLoading(false);
      }
    };

    initializeAppwrite();
  }, [sessionSecret, currentUserId]);
empty shore
#

Are you getting any errors?

cerulean fox
empty shore
#

If you go in the network tab, click WS, find the Appwrite websocket and send a screenshot of what's in there

cerulean fox
empty shore
empty shore
#

can you click into the newest one and show the messages being sent?

empty shore
#

I mean like this

cerulean fox
empty shore
#

Do you have any that show authentication and the response

#

Like what I have in my screenshot

cerulean fox
kindred willow
kindred willow
cerulean fox
kindred willow
#

and so maybe you're not getting anything because an unauthenticated user doesn't have access

empty shore
#

If you set your Appwrite instance to use the same domain as your app and set the session as a cookie it should work. Otherwise you can set the session as the sesion fallback in localstorage and that would work

cerulean fox
cerulean fox
#

I'm talking about the 2nd option, as I don't have any domain now.

empty shore
cerulean fox
empty shore
#

[SOLVED] Realtime feature not working