import { appConfigDir } from '@tauri-apps/api/path'; import { Stronghold } from '@tauri-apps/plugin-stronghold'; import { useState } from 'react'; import { Resolver, useForm } from 'react-hook-form'; import { Link, useNavigate } from 'react-router-dom'; import { User } from '@app/auth/components/user'; import { useStorage } from '@libs/storage/provider'; import { ArrowRightCircleIcon, EyeOffIcon, EyeOnIcon, LoaderIcon } from '@shared/icons'; 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 UnlockScreen() { const navigate = useNavigate(); const setPrivkey = useStronghold((state) => state.setPrivkey); const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); const { db } = useStorage(); const { register, setError, handleSubmit, formState: { errors, isDirty, isValid }, } = useForm({ resolver }); const onSubmit = async (data: { [x: string]: string }) => { setLoading(true); if (data.password.length > 3) { try { const dir = await appConfigDir(); const stronghold = await Stronghold.load(`${dir}/lume.stronghold`, data.password); if (!db.secureDB) db.secureDB = stronghold; const privkey = await db.secureLoad(db.account.pubkey); setPrivkey(privkey); // redirect to home navigate('/', { replace: true }); } catch (e) { setError('password', { type: 'custom', message: e, }); } } else { setError('password', { type: 'custom', message: 'Password is required and must be greater than 3', }); } setLoading(false); }; return (

Enter password to unlock

{errors.password &&

{errors.password.message}

}
Reset password
); }