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?
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.
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
- Locked out of account
Hey guys, I have a paid account and have been locked out. Apologies for using this method, but I'm getting no response via the contact us page. I had a old do...
- Migration from cloud to self-hosted fail...
Hi! I'm trying to migrate a small project from the cloud to a self hosted instance to play around but without any success! The migration process fails with the ...
- Feedback and Deployment Challenges with ...
Hello world!, I've been developing a project using FastAPI in Python, and I was considering deploying it through Appwrite Functions. However, I encountered a f...