Hi,
In Part 2 video of “React & Moralis” the Moralis signup() function is used with the fields email and password. The Moralis docu shows username and password as required and email as optional.
The signup() function has no parameters mentioned.
I get (logicaly) the error: “Cannot sign up user with an empty username.”.
This is solved when i add the variables email (as 1st + 3th param) and password (as 2nd param) in the signup() call.
Video is not consistent: in the part (hereafter, 10:56) to add Login, this solution is visible in the video…. Please correct the video at 9:07 the params are not visible.
Code from video in file App.js:
const SignUp = () => {
const { signup } = useMoralis();
const [email, setEmail] = useState();
const [password, setPassword] = useState();
return (
<Box>
<Input placeholder="Email" value={email} onChange={event => setEmail(event.currentTarget.value)} />
<Input placeholder="Password" type="password" value={password} onChange={event => setPassword(event.currentTarget.value)} />
<Button onClick={() => signup()}>Sign up</Button>
</Box>
);
}
Corrected (working) version:
const SignUp = () => {
const { signup } = useMoralis();
const [email, setEmail] = useState();
const [password, setPassword] = useState();
return (
<Box>
<Input placeholder="Email" value={email} onChange={event => setEmail(event.currentTarget.value)} />
<Input placeholder="Password" type="password" value={password} onChange={event => setPassword(event.currentTarget.value)} />
<Button onClick={() => signup(email, password, email)}>Sign up</Button>
</Box>
);
}
Am i right?
Video: https://youtu.be/FaTyOg7ickc
signup docu: https://docs.moralis.io/moralis-server/users/email-login#sign-up-with-username
useState: https://reactjs.org/docs/hooks-state.html