fix: delete existing user sessions before creating new ones
Fixes issue where games failed to start on iPhone with "No active session found" error. The problem was a UNIQUE constraint on arcade_sessions.user_id - when users tried to start a new game, the session creation would fail silently because they already had an existing session from a previous game. Solution: Delete any existing sessions for the user before creating a new one. This ensures users can start new games without being blocked by stale sessions. Error logs showed: - "UNIQUE constraint failed: arcade_sessions.user_id" - "Failed to fetch session" - "Move rejected: No active session found" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -98,6 +98,10 @@ export async function createArcadeSession(
|
||||
user = newUser
|
||||
}
|
||||
|
||||
// Delete any existing sessions for this user (to handle UNIQUE constraint on userId)
|
||||
// This ensures the user can start a new game session
|
||||
await db.delete(schema.arcadeSessions).where(eq(schema.arcadeSessions.userId, user.id))
|
||||
|
||||
const newSession: schema.NewArcadeSession = {
|
||||
roomId: options.roomId, // PRIMARY KEY - one session per room
|
||||
userId: user.id, // Use the actual database ID, not the guestId
|
||||
|
||||
Reference in New Issue
Block a user