[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
- Which flutter SDK version for Self Hoste...
Hi all, Is there a good way to figure out which version of flutter SDK and Dart SDK is current for latest available self-hosted 1.8.0 ? I know new features are...
- Google Auth not working in a React App
Authentication with Google has failed. It redirects back to the signin route in React. Attached screenshots for configuration of Google console and Appwrite Go...
- Bug Report: Crash when trying to createR...
https://github.com/appwrite/sdk-for-android/issues/96 I think the bug is related with this one https://discord.com/channels/564160730845151244/1443887021314539...