Skip to content

Commit 2c31260

Browse files
fixes
1 parent c5e8953 commit 2c31260

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/routes/blog/post/uber-clone-nextjs-appwrite/+page.markdoc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,14 @@ When a driver accepts a ride, two drivers could try to accept the same ride at t
416416
export async function acceptRideAction(rideId: string, driverId: string) {
417417
const tablesDB = getAdminClient();
418418

419+
// Read the ride to get the riderId for scoped permissions
420+
const current = await tablesDB.getRow({
421+
databaseId: DATABASE_ID,
422+
tableId: RIDES_TABLE_ID,
423+
rowId: rideId,
424+
});
425+
const riderId = current.riderId as string;
426+
419427
// Use a transaction to prevent two drivers accepting the same ride
420428
const tx = await tablesDB.createTransaction();
421429

@@ -427,10 +435,9 @@ export async function acceptRideAction(rideId: string, driverId: string) {
427435
rowId: rideId,
428436
data: { driverId, status: 'accepted' },
429437
permissions: [
430-
Permission.read(Role.user(driverId)),
431-
Permission.update(Role.user(driverId)),
432438
Permission.read(Role.users()),
433-
Permission.update(Role.users()),
439+
Permission.update(Role.user(riderId)),
440+
Permission.update(Role.user(driverId)),
434441
],
435442
transactionId: tx.$id,
436443
});

0 commit comments

Comments
 (0)