signup.js
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import * as auth from "../api/auth";
import push from "next/router";
export default function Signup() {
return (
<div>
<h1>Signup</h1>
<form onSubmit={handleSubmit}>
<label htmlFor="name">Name</label>
<input type="text" id="name" />
<br />
<label htmlFor="email">Email</label>
<input type="email" id="email" />
<br />
<label htmlFor="password">Password</label>
<input type="password" id="password" />
<br />
<label htmlFor="password-confirm">Confirm Password</label>
<input type="password" id="password-confirm" />
<br />
<button type="submit">Signup</button>
</form>
</div>
);
}
function handleSubmit(event) {
event.preventDefault();
const form = event.target;
const name = form.name.value;
const email = form.email.value;
const password = form.password.value;
const passwordConfirm = form.passwordConfirm.value;
console.log(name, email, password, passwordConfirm);
if (password !== passwordConfirm) {
alert("Passwords do not match");
return;
}
const signup = auth.signup(name, email, password);
if(!signup) {
alert("Signup failed");
}
else {
alert("Signup success");
return push("/");
}
}