From ebc399776d7f36d61606f512a896f4a74087f628 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 16 May 2025 13:55:12 -0500 Subject: [PATCH] Fix SignupDialog (so it logs the user in immediately after generating the key) --- src/components/auth/SignupDialog.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/auth/SignupDialog.tsx b/src/components/auth/SignupDialog.tsx index bbe8ca5..0cf73ea 100644 --- a/src/components/auth/SignupDialog.tsx +++ b/src/components/auth/SignupDialog.tsx @@ -12,6 +12,7 @@ import { DialogTitle, } from '@/components/ui/dialog.tsx'; import { toast } from '@/hooks/useToast.ts'; +import { useLoginActions } from '@/hooks/useLoginActions'; import { generateSecretKey, nip19 } from 'nostr-tools'; interface SignupDialogProps { @@ -22,19 +23,19 @@ interface SignupDialogProps { const SignupDialog: React.FC = ({ isOpen, onClose }) => { const [step, setStep] = useState<'generate' | 'download' | 'done'>('generate'); const [isLoading, setIsLoading] = useState(false); - const [nsecKey, setNsecKey] = useState(''); + const [nsec, setNsec] = useState(''); + const login = useLoginActions(); // Generate a proper nsec key using nostr-tools const generateKey = () => { setIsLoading(true); try { - // Generate a new private key - const privateKey = generateSecretKey(); + // Generate a new secret key + const sk = generateSecretKey(); // Convert to nsec format - const nsec = nip19.nsecEncode(privateKey); - setNsecKey(nsec); + setNsec(nip19.nsecEncode(sk)); setStep('download'); } catch (error) { console.error('Failed to generate key:', error); @@ -50,7 +51,7 @@ const SignupDialog: React.FC = ({ isOpen, onClose }) => { const downloadKey = () => { // Create a blob with the key text - const blob = new Blob([nsecKey], { type: 'text/plain' }); + const blob = new Blob([nsec], { type: 'text/plain' }); const url = globalThis.URL.createObjectURL(blob); // Create a temporary link element and trigger download @@ -71,6 +72,8 @@ const SignupDialog: React.FC = ({ isOpen, onClose }) => { }; const finishSignup = () => { + login.nsec(nsec); + setStep('done'); onClose(); @@ -118,7 +121,7 @@ const SignupDialog: React.FC = ({ isOpen, onClose }) => { {step === 'download' && (
- {nsecKey} + {nsec}