Skip to content

Commit fd967c6

Browse files
wesbillmannpub1cl47vfhsqpqy9pwndphpm36vcp7vvz5h2js4qpqm5yewzj7nutkq7xyw8c
andauthored
feat(desktop): gate sign-out behind key backup + typed confirmation (#2424)
Signed-off-by: Wes <[email protected]> Co-authored-by: npub1cl47vfhsqpqy9pwndphpm36vcp7vvz5h2js4qpqm5yewzj7nutkq7xyw8c <c7ebe626f000404285d3686e1dc74cc07cc60a9754a150041ba132e14bd3e2ec@buzz.block.builderlab.xyz>
1 parent c96ae0e commit fd967c6

7 files changed

Lines changed: 423 additions & 105 deletions

File tree

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export default defineConfig({
109109
"**/onboarding-agent-defaults.spec.ts",
110110
"**/nostr-bind.spec.ts",
111111
"**/profile-nsec-reveal.spec.ts",
112+
"**/signout-confirmation.spec.ts",
112113
"**/agent-provider-dropdowns.spec.ts",
113114
"**/agent-lifecycle-feedback.spec.ts",
114115
"**/inbox-live-update.spec.ts",

‎desktop/scripts/check-file-sizes.mjs‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,6 @@ const overrides = new Map([
378378
// observable (propagate real errors); verify_fully_wiped checks all three
379379
// keychain shapes (main blob, DPK blob, per-key "identity"). +73 lines.
380380
["src-tauri/src/secret_store.rs", 1307],
381-
// sign-out wipe: Sign Out section (AlertDialog + controlled state) added
382-
// at the bottom of the Profile settings page. Load-bearing UX feature;
383-
// queued to split when ProfileSettingsCard is broken into sub-components.
384-
// +20 lines: scroll-position save/restore across avatar editor open/close
385-
// to prevent layout shift from the Sign Out section causing a viewport jump.
386-
// +11 lines: signout-dev-webview-state — clear localStorage/sessionStorage
387-
// on successful signOut() resolve so dev-build webview state doesn't survive
388-
// a reset and vouch for the fresh key. Comment explains the race/redundancy.
389-
["src/features/settings/ui/ProfileSettingsCard.tsx", 1044],
390381
// keyring-dev-isolation: keyring_service() fn (7 lines) replaces the const
391382
// to return "buzz-desktop-dev" in debug builds. Load-bearing isolation fix.
392383
// +10 (1042 -> 1052): media_fetch_client with redirect::Policy::none() so a

‎desktop/src/features/onboarding/ui/NsecMaskedDisplay.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ type NsecMaskedDisplayProps = {
77
nsec: string;
88
/** "bare" drops the boxed chrome for the onboarding spotlight treatment. */
99
variant?: "boxed" | "bare";
10+
/**
11+
* Called when the user reveals or copies the key. Lets flows that require
12+
* a backup (e.g. sign-out) gate on actual interaction with the key.
13+
*/
14+
onKeyInteraction?: () => void;
1015
};
1116

1217
export const ONBOARDING_KEY_FRAME_CLASS =
@@ -25,6 +30,7 @@ export const ONBOARDING_KEY_TEXT_CLASS = "buzz-onboarding-key-text";
2530
export function NsecMaskedDisplay({
2631
nsec,
2732
variant = "boxed",
33+
onKeyInteraction,
2834
}: NsecMaskedDisplayProps) {
2935
const [isRevealed, setIsRevealed] = React.useState(false);
3036
const [isCopied, setIsCopied] = React.useState(false);
@@ -40,11 +46,13 @@ export function NsecMaskedDisplay({
4046
}, []);
4147

4248
function handleRevealToggle() {
49+
if (!isRevealed) onKeyInteraction?.();
4350
setIsRevealed((prev) => !prev);
4451
}
4552

4653
async function handleCopy() {
4754
await writeTextToClipboard(nsec);
55+
onKeyInteraction?.();
4856
setIsCopied(true);
4957
if (copyTimerRef.current) clearTimeout(copyTimerRef.current);
5058
copyTimerRef.current = setTimeout(() => setIsCopied(false), 2000);

‎desktop/src/features/settings/ui/ProfileSettingsCard.tsx‎

Lines changed: 3 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,19 @@ import {
1313
useUpdateProfileMutation,
1414
} from "@/features/profile/hooks";
1515
import { NsecMaskedDisplay } from "@/features/onboarding/ui/NsecMaskedDisplay";
16-
import { getNsec, signOut } from "@/shared/api/tauriIdentity";
17-
import {
18-
AlertDialog,
19-
AlertDialogAction,
20-
AlertDialogCancel,
21-
AlertDialogContent,
22-
AlertDialogDescription,
23-
AlertDialogFooter,
24-
AlertDialogHeader,
25-
AlertDialogTitle,
26-
} from "@/shared/ui/alert-dialog";
16+
import { getNsec } from "@/shared/api/tauriIdentity";
2717
import { MaskedAvatarBadgeFrame } from "@/features/profile/ui/MaskedAvatarBadgeFrame";
2818
import { ProfileAvatar } from "@/features/profile/ui/ProfileAvatar";
2919
import {
3020
ProfileAvatarEditor,
3121
parseEmojiAvatarDataUrl,
3222
} from "@/features/profile/ui/ProfileAvatarEditor";
3323
import { cn } from "@/shared/lib/cn";
34-
import { Button } from "@/shared/ui/button";
3524
import { Input } from "@/shared/ui/input";
3625
import { Spinner } from "@/shared/ui/spinner";
3726
import { Textarea } from "@/shared/ui/textarea";
3827
import { SettingsSectionHeader } from "./SettingsSectionHeader";
28+
import { SignOutSection } from "./SignOutSection";
3929
import { writeTextToClipboard } from "@/shared/lib/clipboard";
4030

4131
type ProfileSettingsCardProps = {
@@ -262,8 +252,6 @@ export function ProfileSettingsCard({
262252
const [shouldRenderAvatarEditor, setShouldRenderAvatarEditor] =
263253
React.useState(false);
264254
const [avatarSquishKey, setAvatarSquishKey] = React.useState(0);
265-
const [isSignOutOpen, setIsSignOutOpen] = React.useState(false);
266-
const [isSignOutPending, setIsSignOutPending] = React.useState(false);
267255
const displayNameInputRef = React.useRef<HTMLInputElement>(null);
268256
const aboutTextareaRef = React.useRef<HTMLTextAreaElement>(null);
269257
const sectionRef = React.useRef<HTMLElement>(null);
@@ -956,88 +944,7 @@ export function ProfileSettingsCard({
956944
</div>
957945
</div>
958946

959-
<div
960-
className="mt-8 border-t border-border/60 pb-6 pt-5"
961-
data-testid="settings-signout"
962-
>
963-
<div className="flex items-center justify-between gap-4 px-1">
964-
<div className="min-w-0 space-y-1">
965-
<h2 className="text-lg font-semibold tracking-tight">Sign out</h2>
966-
<p className="text-sm text-muted-foreground">
967-
Removes your identity key and all local app data from this device.
968-
Back up your private key (nsec) first — this cannot be undone.
969-
</p>
970-
</div>
971-
<Button
972-
className="shrink-0"
973-
data-testid="signout-open-dialog"
974-
disabled={isSignOutPending}
975-
onClick={() => setIsSignOutOpen(true)}
976-
type="button"
977-
variant="destructive"
978-
>
979-
{isSignOutPending ? (
980-
<Spinner aria-label="Signing out" className="h-4 w-4 border-2" />
981-
) : null}
982-
{isSignOutPending ? "Signing out…" : "Sign Out"}
983-
</Button>
984-
</div>
985-
<AlertDialog
986-
onOpenChange={(open) => {
987-
if (!open && !isSignOutPending) setIsSignOutOpen(false);
988-
}}
989-
open={isSignOutOpen}
990-
>
991-
<AlertDialogContent>
992-
<AlertDialogHeader>
993-
<AlertDialogTitle>Sign out and wipe all data?</AlertDialogTitle>
994-
<AlertDialogDescription>
995-
This will delete your identity key, all agent settings, and
996-
cached data from this device, then relaunch Buzz into first-run
997-
setup. Make sure you have your private key (nsec) backed up
998-
before continuing — this cannot be undone.
999-
</AlertDialogDescription>
1000-
</AlertDialogHeader>
1001-
<AlertDialogFooter>
1002-
<AlertDialogCancel disabled={isSignOutPending}>
1003-
Cancel
1004-
</AlertDialogCancel>
1005-
<AlertDialogAction
1006-
className="bg-destructive text-destructive-foreground shadow-xs hover:bg-destructive/90"
1007-
data-testid="signout-confirm"
1008-
disabled={isSignOutPending}
1009-
onClick={() => {
1010-
setIsSignOutPending(true);
1011-
// Keep the pending state if signOut() resolves before restart.
1012-
signOut()
1013-
.then(() => {
1014-
// Clear web storage for this origin on the success path
1015-
// only. This covers dev builds where the Rust webview wipe
1016-
// targets the .app-bundle WebKit dir (missing in `tauri
1017-
// dev`), preventing stale community config from vouching
1018-
// for the fresh key on next boot. In production the Rust
1019-
// wipe already handles this; the clear here is redundant
1020-
// but harmless. The restart may race this clear — that is
1021-
// acceptable; Fix A (pubkey-scoped heuristic) is the
1022-
// correctness gate.
1023-
window.localStorage.clear();
1024-
window.sessionStorage.clear();
1025-
})
1026-
.catch((err: unknown) => {
1027-
setIsSignOutPending(false);
1028-
setIsSignOutOpen(false);
1029-
toast.error(
1030-
err instanceof Error ? err.message : "Sign out failed.",
1031-
);
1032-
});
1033-
}}
1034-
>
1035-
{isSignOutPending ? "Signing out…" : "Delete My Data"}
1036-
</AlertDialogAction>
1037-
</AlertDialogFooter>
1038-
</AlertDialogContent>
1039-
</AlertDialog>
1040-
</div>
947+
<SignOutSection />
1041948
</section>
1042949
);
1043950
}

0 commit comments

Comments
 (0)