import { usePassphraseAuth } from "jazz-tools/react-core"; import { useState } from "react"; export function PassphraseAuthBasicUI(props: { appName: string; wordlist: string[]; children?: React.ReactNode; }) { const auth = usePassphraseAuth({ wordlist: props.wordlist, }); const [step, setStep] = useState<"initial" | "create" | "login">("initial"); const [loginPassphrase, setLoginPassphrase] = useState(""); const [isCopied, setIsCopied] = useState(false); if (auth.state === "signedIn") { return props.children ?? null; } const handleCreateAccount = async () => { setStep("create"); }; const handleLogin = () => { setStep("login"); }; const handleBack = () => { setStep("initial"); setLoginPassphrase(""); }; const handleCopy = async () => { await navigator.clipboard.writeText(auth.passphrase); setIsCopied(true); }; const handleLoginSubmit = async () => { await auth.logIn(loginPassphrase); // Sets the state to signed in // Reset the state in case of logout setStep("initial"); setLoginPassphrase(""); }; const handleNext = async () => { await auth.signUp(); // Sets the state to signed in // Reset the state in case of logout setStep("initial"); setLoginPassphrase(""); }; return (
Please copy and store this passphrase somewhere safe. You'll need it to log in.