fix(devices): keep the existing device name on re-pair and re-login

A dedupe-keyed client re-mint (QR rescan, password/passkey re-login) replaces
the stored record, which also reset the operator-visible name to the app's
hardcoded default ('OpenChamber Mobile'). The app-reported name is now only a
fallback: an explicit pairing label wins, otherwise the replaced record's
label is kept, and the default applies only to a first-ever pairing.
This commit is contained in:
Bohdan Triapitsyn
2026-08-24 14:03:18 +03:00
parent 5fa6f2c159
commit 3aa45805bc
6 changed files with 43 additions and 13 deletions
@@ -157,6 +157,7 @@ export const createRemoteClientAuthRuntime = ({ fsPromises, path, crypto, storeP
const createClient = async ({
label,
fallbackLabel,
expiresAt,
clientKind,
dedupeKey,
@@ -172,9 +173,16 @@ export const createRemoteClientAuthRuntime = ({ fsPromises, path, crypto, storeP
const store = await readStore();
const normalizedDedupeKey = normalizeOptionalString(dedupeKey);
const token = generateToken();
// A dedupe-keyed mint REPLACES the previous record for the same device,
// so an operator-visible name must survive the replacement: an explicit
// label wins, otherwise the replaced record's label is kept, and only a
// first-ever mint falls back to the client-reported default.
const existing = normalizedDedupeKey
? store.clients.find((entry) => entry.dedupeKey === normalizedDedupeKey)
: null;
const client = {
id: generateId(),
label: normalizeLabel(label),
label: normalizeLabel(normalizeOptionalString(label) || existing?.label || fallbackLabel),
tokenHash: hashToken(token),
createdAt: nowIso(),
lastUsedAt: null,