fix(arcade): allow deactivating players from users who left the room
**Root Cause:** The validation was checking if player.userId matches a current room member. This failed when: - User joins room with active players - User leaves room - Their players remain in GameModeContext as 'remote players' - Host tries to deactivate them **Fix:** Remove the 'player belongs to room member' check. Host should be able to deactivate ANY player except their own, including orphaned players from users who have left. **Validation now:** - ✓ Player exists in database - ✓ Player is not owned by the current viewer (can't deactivate your own) - ✓ User is the room host This allows hosts to clean up orphaned players and restore proper game state. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ee874876e4
commit
7c1c2d7beb
|
|
@ -65,26 +65,19 @@ export async function POST(req: NextRequest, context: RouteContext) {
|
|||
members.map((m) => m.userId)
|
||||
)
|
||||
|
||||
// Find which user owns this player
|
||||
const playerOwnerMember = members.find((m) => m.userId === player.userId)
|
||||
console.log('[Deactivate Player API] Player owner member:', playerOwnerMember)
|
||||
|
||||
if (!playerOwnerMember) {
|
||||
console.log('[Deactivate Player API] ERROR: Player userId does not match any room member')
|
||||
return NextResponse.json(
|
||||
{ error: 'Player does not belong to a room member' },
|
||||
{ status: 404 }
|
||||
)
|
||||
}
|
||||
|
||||
// Can't deactivate your own players (use the regular player controls for that)
|
||||
if (player.userId === viewerId) {
|
||||
console.log('[Deactivate Player API] ERROR: Cannot deactivate your own players')
|
||||
return NextResponse.json(
|
||||
{ error: 'Cannot deactivate your own players. Use the player controls in the nav.' },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
// Note: We don't check if the player belongs to a current room member
|
||||
// because players from users who have left the room may still need to be cleaned up
|
||||
console.log('[Deactivate Player API] Player validation passed, proceeding with deactivation')
|
||||
|
||||
// Deactivate the player
|
||||
await setPlayerActiveStatus(body.playerId, false)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue