Skip to content
Back

[Flutter] Realtime Not Working with User Permissions (Works with Guest/Any)

  • 0
  • Flutter
  • Realtime
Kushal Kumar
25 Sep, 2025, 17:40

Hello Appwrite community! I have a "chores" app. When User A adds a chore to a shared list, I want it to appear instantly on User B's screen without them needing to refresh. Real-time updates are not being received by other users. However, if I manually refresh the screen, the new chore appears correctly, which proves that the basic database read permissions are working. If I set the chores collection's read permission to Any or Guests, the real-time updates work perfectly. As soon as I restrict it to authenticated users (Users), the real-time events stop, even though the users are logged in and can fetch the data when refreshing. I'm trying to follow the simple pattern used in many working chat apps.

  1. Flutter Client (chore_state_notifier.dart) - Subscribing

My Flutter app subscribes directly to the chores collection. `// lib/features/chores/presentation/providers/chore_state_notifier.dart

void _subscribeToChoreUpdates() { final realtime = _ref.read(appwriteRealtimeProvider); final databaseId = AppwriteConstants.databaseId; final collectionId = AppwriteConstants.choresCollectionId;

TypeScript
// Subscribing directly to the chores collection
final channel = 'databases.$databaseId.collections.$collectionId.documents';

_subscription = realtime.subscribe([channel]);

_subscription!.stream.listen((response) {
  **// THIS PRINT STATEMENT NEVER APPEARS FOR OTHER USERS**
  print("<<<<< DIRECT REALTIME EVENT RECEIVED: ${response.payload} >>>>>");
  
  // ... logic to update the UI state
});

}`

Logs: I/flutter (20357): Received heartbeat response from realtime server I/flutter (20357): subscription: wss://fra.cloud.appwrite.io/v1/realtime?project=xxxx&channels%5B%5D=databases.xxxx.collections.chores.documents I/flutter (20357): subscription: wss://fra.cloud.appwrite.io/v1/realtime?project=xxxx&channels%5B%5D=databases.xxxx.collections.chores.documents&channels%5B%5D=databases.xxxx.collections.choreLists.documents

TL;DR
Developers experiencing real-time update issues with Flutter when using specific user permissions. Real-time updates work with 'Any' or 'Guest' access but fail with authenticated users. Manually refreshing the screen shows the new chore, proving basic permissions work. Flutter client subscribes directly to the chores collection, but the real-time event print statement only appears for the user triggering the event, not others. Solution: Ensure permissions or real-time subscription logic correctly handle user authentication for real-time updates to work across all users.
Kushal Kumar
25 Sep, 2025, 17:44
  1. Appwrite Function (mergedFunction/src/main.js) - Setting Permissions

When a user creates a chore, my app calls an Appwrite function. The function's only job is to create the chore document and add a specific, individual read permission for every member of that chore list.

Function code: `case 'createChore': { const { choreData } = data; const currentUser = await account.get(); const userId = currentUser.$id; const { id = ID.unique(), description, points = 0, type = 'daily', deadline = null, lastCompletedAt = null, resetDurationInSeconds = null, choreListId, } = choreData; const userDatabases = new Databases(userClient);

TypeScript
    const choreListDoc = await userDatabases.getDocument(
      APPWRITE_DATABASE_ID,
      CHORE_LISTS_COLLECTION_ID,
      choreListId
    );
    const teamId = choreListDoc.teamId;

    // 1. Get all members of the team.
    const teamMemberships = await teams.listMemberships(teamId);
    const members = teamMemberships.memberships;
    console.log(`Found ${members.length} members in the team.`);

    // 2. An array of specific read permissions for EACH member.       
    const memberReadPermissions = members.map(member => 
        Permission.read(`user:${member.userId}`)
    );
    console.log(`Created ${memberReadPermissions.length} individual read permissions.`);`
Kushal Kumar
25 Sep, 2025, 17:44

` const newChore = await databases.createDocument( APPWRITE_DATABASE_ID, CHORES_COLLECTION_ID, id, { id, description, isDone: false, points, type, deadline, lastCompletedAt, resetDurationInSeconds, userId, choreListId, }, [ ...memberReadPermissions,

TypeScript
        Permission.update(Role.team(teamId, "editor")),
        Permission.update(Role.team(teamId, "owner")),
        Permission.delete(Role.team(teamId, "editor")),
        Permission.delete(Role.team(teamId, "owner")),
      ]
    );
      console.log(`Chore created with ID: ${newChore.$id}`);
      console.log(`Final permissions on document: ${JSON.stringify(newChore.$permissions)}`);
      console.log("--- Finished CreateChore ---");
      return context.res.json({
        ok: true,
        message: 'Chore created successfully.',
        choreId: newChore.$id
      });
  }``

Log output: Found 2 members in the team. Created 2 individual read permissions. Chore created with ID: 68d574f73413bfd0e403 Final permissions on document: ["read(\"user:xxxx\")","read(\"user:xxxx\")","update(\"team:xxxx/editor\")","update(\"team:xxxx/owner\")","delete(\"team:xxxx/editor\")","delete(\"team:xxxx/owner\")"] --- Finished CreateChore ---

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