diff --git a/convex/machines.ts b/convex/machines.ts index 7cf3413..3428759 100644 --- a/convex/machines.ts +++ b/convex/machines.ts @@ -2731,12 +2731,19 @@ export const upsertRemoteAccessViaToken = mutation({ const cleanedNotes = args.notes?.trim() ? args.notes.trim() : null const timestamp = Date.now() const existingEntries = normalizeRemoteAccessList(machine.remoteAccess) - const existingIndex = existingEntries.findIndex( + let existingIndex = existingEntries.findIndex( (entry) => entry.provider.toLowerCase() === trimmedProvider.toLowerCase() && entry.identifier.toLowerCase() === trimmedIdentifier.toLowerCase() ) + // Se o identificador mudar (ex.: RustDesk gerando novo ID), reaproveitamos a entrada do mesmo provider + if (existingIndex < 0) { + existingIndex = existingEntries.findIndex( + (entry) => entry.provider.toLowerCase() === trimmedProvider.toLowerCase() + ) + } + const entryId = existingIndex >= 0 ? existingEntries[existingIndex].id : createRemoteAccessId() const updatedEntry: RemoteAccessEntry = { id: entryId,