import { appConfigDir } from '@tauri-apps/api/path'; import { useEffect, useState } from 'react'; import { Resolver, useForm } from 'react-hook-form'; import { useNavigate } from 'react-router-dom'; import { Stronghold } from 'tauri-plugin-stronghold-api'; import { useStorage } from '@libs/storage/provider'; import { EyeOffIcon, EyeOnIcon, LoaderIcon } from '@shared/icons'; import { ArrowRightCircleIcon } from '@shared/icons/arrowRightCircle'; import { useOnboarding } from '@stores/onboarding'; import { useStronghold } from '@stores/stronghold'; type FormValues = { password: string; }; const resolver: Resolver = async (values) => { return { values: values.password ? values : {}, errors: !values.password ? { password: { type: 'required', message: 'This is required.', }, } : {}, }; }; export function CreateStep2Screen() { const navigate = useNavigate(); const setStep = useOnboarding((state) => state.setStep); const pubkey = useOnboarding((state) => state.pubkey); const privkey = useStronghold((state) => state.privkey); const [passwordInput, setPasswordInput] = useState('password'); const [loading, setLoading] = useState(false); const { db } = useStorage(); // toggle private key const showPassword = () => { if (passwordInput === 'password') { setPasswordInput('text'); } else { setPasswordInput('password'); } }; const { register, setError, handleSubmit, formState: { errors, isDirty, isValid }, } = useForm({ resolver }); const onSubmit = async (data: { [x: string]: string }) => { setLoading(true); if (data.password.length > 3) { const dir = await appConfigDir(); const stronghold = await Stronghold.load(`${dir}lume.stronghold`, data.password); if (!db.secureDB) db.secureDB = stronghold; // save privkey to secure storage await db.secureSave(pubkey, privkey); // redirect to next step navigate('/auth/create/step-3', { replace: true }); } else { setLoading(false); setError('password', { type: 'custom', message: 'Password is required and must be greater than 3', }); } }; useEffect(() => { // save current step, if user close app and reopen it setStep('/auth/create/step-2'); }, []); return (

Set password to secure your key

Password is not related to your Nostr account. It is only used to secure your keys stored on your local machine and to unlock the app (like unlocking your phone with a passcode). When you move to other Nostr clients, you just need to copy your private key.

{errors.password &&

{errors.password.message}

}
); }