Skip to content
Back

subscribe collections with session login client side

  • 0
  • Self Hosted
  • Web
elemin67
3 Mar, 2025, 02:08

im trying to subscribe only to user related documents. Document security is enabled. But I get any updates.

I recive also documents from other user

nextjs:

TypeScript
 const { client } = getClientSideServices();
  
  return client.subscribe(
`databases.${appwriteConfig.databaseId}.collections.${collectionId}.documents`,
    (response) => {
      console.log('Events get for :', collectionId, response);
      callback(response);
    }
  );

and

TypeScript
export function getClientSideServices() {
  const client = new Client()
    .setEndpoint(appwriteConfig.endpoint)
    .setProject(appwriteConfig.projectId);

  const sessionCookie = getCookie('session');
  if (sessionCookie) {
    console.log('Session-Cookie found, last Session:', sessionCookie.substring(0, 10) + '...');
    client.setSession(sessionCookie);
  } else {
    console.warn('No Session-Cookie found!');
  }

  return {
    account: new Account(client),
    databases: new Databases(client),
    storage: new Storage(client),
    teams: new Teams(client),
    client,
  };
}
TL;DR
Developers are having issues subscribing to user-related documents with session login on the client side. They suspect the null user could be the reason why. The developers tried following a tutorial, but it didn't help. Despite having document security enabled, they are still receiving updates from other users. Solution: The code provided seems to set the session cookie based on the client-side session; developers may need to troubleshoot the session handling and ensure proper authentication to prevent receiving updates from other users.
elemin67
3 Mar, 2025, 02:38

permissions on collection settings:

elemin67
3 Mar, 2025, 02:38
elemin67
3 Mar, 2025, 02:39

permissions on document settings:

elemin67
3 Mar, 2025, 02:39
elemin67
3 Mar, 2025, 02:41

I followed also this tutorial. It doesnt helped

elemin67
3 Mar, 2025, 02:51

I checked also dev tools on browser. the user is null. Is that the reason? If yes, how can we fix it?

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