SkateSpots/src/lib/backup.ts
SkateSpots a2bc42c94b fix(onboarding): stop the first-run checklist + backup reminder nagging returning users
- FirstRunChecklist showed to any logged-in user until manually dismissed; it now
  requires a recent signup_completed stamp AND first-run-seen (auto, once), so
  established/imported accounts never see it.
- SignupDialog wrote the backup-confirmed flag under user?.pubkey while the login
  was still settling, so it landed on 'backup-confirmed:anon' and the post-signup
  BackupReminder nagged every session. Now markBackupConfirmed() is called with the
  pubkey derived from the minted nsec.
- NIP-49 export password field autoComplete new-password -> off (fewer browser
  save-password prompts).
2026-10-12 23:11:42 +07:00

28 lines
1.1 KiB
TypeScript

/**
* Per-account key for the "I've saved my recovery code" flag.
*
* It MUST be namespaced by pubkey: a device-global flag let account A's
* confirmation suppress the backup reminder for account B created later on the
* same device — leaving B's only key unrecovered.
*/
export function backupConfirmedKey(pubkey: string | undefined): string {
return `backup-confirmed:${pubkey ?? 'anon'}`;
}
/**
* Record that this account's key was saved.
*
* ⚠️ Call this with the **real** pubkey (e.g. derived from the freshly minted
* nsec), NOT `useCurrentUser().pubkey` during signup — at that moment `user` is
* still settling, so the write landed on `backup-confirmed:anon` and the
* post-signup reminder never learned the key was saved (it nagged every session).
* Mirrors `useLocalStorage`'s JSON encoding so the hook reads it back.
*/
export function markBackupConfirmed(pubkey: string | undefined): void {
if (!pubkey) return;
try {
localStorage.setItem(backupConfirmedKey(pubkey), JSON.stringify(true));
} catch {
// localStorage can throw in strict privacy modes — safe to ignore.
}
}