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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user