1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-24 15:17:41 +01:00
smov/src/pages/parts/auth/VerifyPassphrasePart.tsx
mrjvs 743ecc7869 authentication register and login
Co-authored-by: William Oldham <github@binaryoverload.co.uk>
2023-11-05 17:56:56 +01:00

51 lines
1.4 KiB
TypeScript

import { useState } from "react";
import { useAsyncFn } from "react-use";
import { Button } from "@/components/Button";
import { Input } from "@/components/player/internals/ContextMenu/Input";
import { useAuth } from "@/hooks/auth/useAuth";
import { AccountProfile } from "@/pages/parts/auth/AccountCreatePart";
interface VerifyPassphraseProps {
mnemonic: string | null;
userData: AccountProfile | null;
onNext?: () => void;
}
export function VerifyPassphrase(props: VerifyPassphraseProps) {
const [mnemonic, setMnemonic] = useState("");
const { register, restore } = useAuth();
const [result, execute] = useAsyncFn(
async (inputMnemonic: string) => {
if (!props.mnemonic || !props.userData)
throw new Error("invalid input data");
if (inputMnemonic !== props.mnemonic)
throw new Error("Passphrase doesn't match");
// TODO captcha?
await register({
mnemonic: inputMnemonic,
userData: props.userData,
});
// TODO import (and sort out conflicts)
await restore();
props.onNext?.();
},
[props, register, restore]
);
return (
<div>
<p>verify passphrase</p>
<Input value={mnemonic} onInput={setMnemonic} />
{result.loading ? <p>Loading...</p> : null}
{result.error ? <p>error: {result.error.toString()}</p> : null}
<Button onClick={() => execute(mnemonic)}>Register</Button>
</div>
);
}