I have a simple form component that is expected to create a new user using the the ###firstName, ###lastName, ###username, and ###password from a react-hook-form application.
Is it possible to create this is user on the click of the form's submit button and have that user created on the appwrite account?
TL;DR
Code sample provided for creating a user account with React hook form. Missing implementation details, and not tested. Need to replace ###firstName, ###lastName, ###username, ###password with correct fields. Possible solution involves calling account.create and account.createEmailPasswordSession within onSubmit, then navigating to the app upon successful creation.Sure, here is a code sample. Just an FYI I did not test this, it's just a concept of how you might accomplish this.
TypeScript
export default function LoginPage() {
const { register, handleSubmit, formState: { errors } } = useForm();
const onSubmit = (data) => {
try {
const user = await account.create(
ID.unique(),
data.email,
data.password,
data.name
);
const session = await account.createEmailPasswordSession(
data.email,
data.password
);
// navigate to app
} catch (err) {
console.error(err);
}
};
return (
<>
<p className="title">Registration Form</p>
<form onSubmit={handleSubmit(onSubmit)}>
<input type="text" {...register("name")} />
<input type="email" {...register("email")} />
<input type="password" {...register("password")} />
<input type={"submit"} />
</form>
</>
);
}
Recommended threads
- Issues with uAuth
Hey everyone, is anyone experiencing 500 errors for the oauth flow starting today? Im in the fra region. My oauth flow used to work fine until today, now im get...
- Provider error when creating a function ...
- Cloud function deployment failures
When I run appwrite push functions, select the function I want to deploy, confirm with a YES, is starts deploying but goes into error. I need to repeat the ste...