Evita múltiplos acessos remotos por provider ao reaproveitar entrada existente

This commit is contained in:
esdrasrenan 2025-12-10 21:19:10 -03:00
parent 81d1a7c7f7
commit b663268791

View file

@ -2731,12 +2731,19 @@ export const upsertRemoteAccessViaToken = mutation({
const cleanedNotes = args.notes?.trim() ? args.notes.trim() : null const cleanedNotes = args.notes?.trim() ? args.notes.trim() : null
const timestamp = Date.now() const timestamp = Date.now()
const existingEntries = normalizeRemoteAccessList(machine.remoteAccess) const existingEntries = normalizeRemoteAccessList(machine.remoteAccess)
const existingIndex = existingEntries.findIndex( let existingIndex = existingEntries.findIndex(
(entry) => (entry) =>
entry.provider.toLowerCase() === trimmedProvider.toLowerCase() && entry.provider.toLowerCase() === trimmedProvider.toLowerCase() &&
entry.identifier.toLowerCase() === trimmedIdentifier.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 entryId = existingIndex >= 0 ? existingEntries[existingIndex].id : createRemoteAccessId()
const updatedEntry: RemoteAccessEntry = { const updatedEntry: RemoteAccessEntry = {
id: entryId, id: entryId,