Skip to content

Commit fd214c7

Browse files
committed
feat: add reset key button and debug logs
1 parent 64bfb01 commit fd214c7

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

src/hooks/useInventoryKey.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,19 @@ export function useInventoryKey() {
181181

182182
// Auto-initialize key if missing
183183
useEffect(() => {
184+
// Debug logging for key initialization state
185+
if (activeUser && process.env.NODE_ENV === 'development') {
186+
console.debug('useInventoryKey check:', {
187+
hasActiveUser: !!activeUser,
188+
isLoadingKeychains,
189+
isLoadingKeys,
190+
hasMyKey: !!myKey,
191+
isInitializing: initializeKey.isPending
192+
});
193+
}
194+
184195
if (activeUser && !isLoadingKeychains && !isLoadingKeys && !myKey && !initializeKey.isPending) {
185-
console.debug('Auto-initializing inventory key');
196+
console.log('Auto-initializing inventory key (NIP-44 Upgrade or Missing Key)');
186197
initializeKey.mutate();
187198
}
188199
}, [activeUser, isLoadingKeychains, isLoadingKeys, myKey, initializeKey.isPending]);

src/pages/Settings.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Button } from '@/components/ui/button';
55
import { Settings as SettingsIcon, ArrowLeft } from 'lucide-react';
66
import { RelayListManager } from '@/components/RelayListManager';
77
import { useCurrentUser } from '@/hooks/useCurrentUser';
8+
import { useInventoryKey } from '@/hooks/useInventoryKey';
89
import { LoginArea } from '@/components/auth/LoginArea';
910

1011
export function Settings() {
@@ -96,7 +97,54 @@ export function Settings() {
9697
</div>
9798
</CardContent>
9899
</Card>
100+
101+
{/* Troubleshooting */}
102+
<Card className="border-0 shadow-xl bg-white/70 dark:bg-slate-800/70 backdrop-blur-sm mt-8">
103+
<CardContent className="pt-6">
104+
<div className="space-y-4">
105+
<div>
106+
<h3 className="text-lg font-semibold text-red-600 dark:text-red-400">Troubleshooting</h3>
107+
<p className="text-muted-foreground text-sm">
108+
If you are experiencing issues with sharing or data persistence (e.g. "Not ready or no personal key"), try resetting your encryption key.
109+
<br /><strong>Warning:</strong> This will invalidate existing shares. You will need to re-share your inventory.
110+
</p>
111+
</div>
112+
<ResetKeyButton />
113+
</div>
114+
</CardContent>
115+
</Card>
99116
</div>
100117
</div>
101118
);
119+
}
120+
121+
function ResetKeyButton() {
122+
const { initializeKey, isLoading, myKey } = useInventoryKey();
123+
const [status, setStatus] = React.useState<string>('');
124+
125+
const handleReset = async () => {
126+
try {
127+
setStatus('Resetting...');
128+
await initializeKey.mutateAsync();
129+
setStatus('Success! Key reset.');
130+
setTimeout(() => setStatus(''), 3000);
131+
} catch (e) {
132+
console.error(e);
133+
setStatus('Error: ' + (e as Error).message);
134+
}
135+
};
136+
137+
return (
138+
<div className="flex items-center gap-4">
139+
<Button
140+
variant="destructive"
141+
onClick={handleReset}
142+
disabled={isLoading || initializeKey.isPending}
143+
>
144+
{initializeKey.isPending ? 'Resetting...' : 'Reset Inventory Key'}
145+
</Button>
146+
{status && <span className="text-sm font-medium">{status}</span>}
147+
{myKey && <span className="text-xs text-green-600">Active Key Present</span>}
148+
</div>
149+
);
102150
}

0 commit comments

Comments
 (0)