This repository was archived by the owner on Jan 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsignup.tsx
79 lines (73 loc) · 3.63 KB
/
signup.tsx
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { FormEvent, useState } from "react";
import Link from 'next/link'
import { useRouter } from "next/router";
import Alert from "../components/alert";
import { appwrite, userState } from "../store/global";
import { useRecoilState } from 'recoil';
import { User } from '../store/types';
const SignUp = () => {
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [alert, setAlert] = useState("");
const [user, setUser] = useRecoilState(userState);
const router = useRouter();
const signup = async (e: FormEvent<EventTarget>) => {
e.preventDefault();
try {
await appwrite.account.create('unique()', email, password, name);
setUser(await appwrite.account.createEmailSession(email, password) as unknown as User);
router.push("/todos");
} catch (error) {
setAlert(error.message);
}
}
return (
<>
{alert && <Alert message={alert} />}
<section className="container h-screen mx-auto flex">
<div className="flex-grow flex flex-col max-w-xl justify-center p-6">
<h1 className="text-6xl font-bold">Sign Up</h1>
<p className="mt-4">
Already have an account?{" "}
<Link href="/login">
<a className="cursor-pointer underline">
Login
</a>
</Link>
</p>
<form onSubmit={signup}>
<label className="block mt-6"> Name</label>
<input
className="w-full p-4 placeholder-gray-400 text-gray-700 bg-white text-lg border-0 border-b-2 border-gray-400 focus:ring-0 focus:border-gray-900"
type="text"
onChange={(e) => setName(e.target.value)}
/>
<label className="block mt-6"> Email</label>
{/* “Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” */}
<input
className="w-full p-4 placeholder-gray-400 text-gray-700 bg-white text-lg border-0 border-b-2 border-gray-400 focus:ring-0 focus:border-gray-900"
type="text"
onChange={(e) => setEmail(e.target.value)}
/>
<label className="block mt-6"> Password</label>
<input
className="w-full p-4 placeholder-gray-400 text-gray-700 bg-white text-lg border-0 border-b-2 border-gray-400 focus:ring-0 focus:border-gray-900"
type="password"
onChange={(e) => setPassword(e.target.value)}
/>
<div className="mt-6">
<button
type="submit"
disabled={!name || !email || !password}
className="mx-auto mt-4 py-4 px-16 font-semibold rounded-lg shadow-md bg-gray-900 text-white border hover:border-gray-900 hover:text-gray-900 hover:bg-white focus:outline-none disabled:opacity-50 disabled:cursor-not-allowed">
Sign Up
</button>
</div>
</form>
</div>
</section>
</>
);
};
export default SignUp;