[SOLVED] AppwriteException: Invalid `email` param: Value must be a valid email address
- 0
- Self Hosted
- Web

import React, { useState } from "react";
import { account } from "../appwrite/appwriteConfig";
import { useNavigate } from "react-router-dom";
import { v4 as uuidv4 } from "uuid";
import "../styles/Login.css";
function Register() {
const navigate = useNavigate();
const [user, setUser] = useState({
name: "",
email: "",
password: "",
});
const isValidEmail = (email) => {
// Regular expression for a simple email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
};
const registerUser = async (e) => {
e.preventDefault();
if (!isValidEmail(user.email)) {
console.log("Invalid email address");
return;
}
const promise = account.create(
uuidv4(),
user.name,
user.email,
user.password
);
promise.then(
(res) => {
console.log(res);
navigate("/todolist");
},
(err) => {
console.log(err);
}
);
};
return (
<div className="landing">
<div className="register">
<h2>Register</h2>
<form onSubmit={registerUser}>
<label htmlFor="name">Name: </label>
<input
type="text"
onChange={(e) => setUser({ ...user, name: e.target.value })}
/>
<label htmlFor="email">Email: </label>
<input
type="email"
onChange={(e) => setUser({ ...user, email: e.target.value })}
/>
<label htmlFor="password">Password: </label>
<input
type="password"
onChange={(e) => setUser({ ...user, password: e.target.value })}
/>
<button type="submit">Register</button>
<p>Already an user?</p>
<button onClick={()=>navigate('/')}>Login</button>
</form>
</div>
</div>
);
}
export default Register;

const promise = account.create(
uuidv4(),
user.name,
user.email,
user.password
);
This is not the correct format. Have a look at the docs for the correct format.

Any reason why you are using the uuid
package instead of the ID.unique()
helper that comes with the appwrite
sdk?

const promise = account.create(
ID.unique(),
user.email,
user.password,
user.name,
);

I was following a tutorial. In the tutorial, he was using a older version of appwrite i guess. Ok i will see the docs and give a try.

still getting the same error
AppwriteException: Invalid `email` param: Value must be a valid email address
at Client.<anonymous> (http://localhost:3000/static/js/bundle.js:49742:17)
at Generator.next (<anonymous>)
at fulfilled (http://localhost:3000/static/js/bundle.js:49376:24)

Which version of Appwrite are you using?

13.0.0 latest i guess

I mean the server version.

1.4.3

Just to be sure, can you share the updated code again?

import React, { useState } from "react";
import { ID } from 'appwrite'
import { account } from "../appwrite/appwriteConfig";
import { useNavigate } from "react-router-dom";
import "../styles/Login.css";
function Register() {
const navigate = useNavigate();
const [user, setUser] = useState({
name: "",
email: "",
password: "",
});
const registerUser = async (e) => {
e.preventDefault();
const promise = account.create(
ID.unique(),
user.name,
user.email,
user.password
);
promise.then(
(res) => {
console.log(res);
navigate("/todolist");
},
(err) => {
console.log(err);
}
);
};
return (
<div className="landing">
<div className="register">
<h2>Register</h2>
<form onSubmit={registerUser}>
<label htmlFor="name">Name: </label>
<input
type="text"
onChange={(e) => setUser({ ...user, name: e.target.value })}
/>
<label htmlFor="email">Email: </label>
<input
type="text"
onChange={(e) => setUser({ ...user, email: e.target.value })}
/>
<label htmlFor="password">Password: </label>
<input
type="password"
onChange={(e) => setUser({ ...user, password: e.target.value })}
/>
<button type="submit">Register</button>
<p>Already an user?</p>
<button onClick={()=>navigate('/')}>Login</button>
</form>
</div>
</div>
);
}
export default Register;

the order is wrong

it needs to be
- id
- password
- name

you’ve done
- id
- name
- password

make sure the order is correct in the account.create
call

ohhhh.. thanks dude you saved the day 🥲

[SOLVED] AppwriteException: Invalid email
param: Value must be a valid email address
Recommended threads
- Custom domain issue
Hello following another post I'm creating dedicated post according to my project ID: 67ffbd800010958ae104 I deployed for debug my React Native app in web, chrom...
- Problem for certificate
Good evening! I installed Appwrite on my hosting via Docker Compose. Then I set up the .env configuration. But for some reason it does not support HTTPS, when l...
- Appwrite DNS Record Invalid on 123reg
So I go to the project settings and add in my domain name. Then when I add the CNAME record to 123reg it says that ''Record data is invalid'' As seen in the s...
