import { EyeOffIcon, EyeOnIcon, LoaderIcon } from "@lume/icons"; import { useStorage } from "@lume/storage"; import { invoke } from "@tauri-apps/api/core"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { Trans, useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import { toast } from "sonner"; export function LoginWithKey() { const storage = useStorage(); const navigate = useNavigate(); const [showKey, setShowKey] = useState(false); const [loading, setLoading] = useState(false); const { t } = useTranslation("loginWithPrivkey.subtitle"); const { register, handleSubmit, setError, formState: { errors, isValid }, } = useForm(); const onSubmit = async (data: { nsec: string }) => { try { if (!data.nsec.startsWith("nsec1")) return toast.error("You need to enter a private key start with nsec1"); setLoading(true); // trigger save key const save = await invoke("save_key", { nsec: data.nsec }); if (!save) { setLoading(false); toast.error("Save account keys failed, please try again later."); } // redirect to next step return navigate("/auth/onboarding", { replace: true }); } catch (e) { setLoading(false); setError("nsec", { type: "manual", message: String(e), }); } }; return (

{t("loginWithPrivkey.title")}

Lume will put your private key to{" "} {storage.platform === "macos" ? "Apple Keychain" : storage.platform === "windows" ? "Credential Manager" : "Secret Service"} . It will be secured by your OS.

{errors.nsec && (

{errors.nsec.message as string}

)}
); }