-
Notifications
You must be signed in to change notification settings - Fork 26
/
Login.tsx
112 lines (105 loc) · 4.97 KB
/
Login.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"use client";
import appwriteService from "@/appwrite/config";
import useAuth from "@/context/useAuth";
import Link from "next/link";
import { useRouter } from "next/navigation";
import React, {FormEvent, useState} from "react";
const Login = () => {
const router = useRouter()
const {setAuthStatus} = useAuth()
const [formData, setFormData] = useState({
email: "",
password: "",
})
const [error, setError] = useState("")
const login = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault()
try {
const session = await appwriteService.login(formData);
if (session) {
setAuthStatus(true)
router.push("/profile")
}
} catch (error: any) {
setError(error.message)
}
}
return (
<div className="flex items-center justify-center w-full">
<div className={`mx-auto w-full max-w-lg bg-gray-200/50 rounded-xl p-10`}>
<div className="mb-2 flex justify-center">
<span className="inline-block w-full max-w-[60px]">
<img src="/favicon.ico" alt="Logo" />
</span>
</div>
<h2 className="text-center text-2xl font-bold leading-tight text-black">
Sign in to your account
</h2>
<p className="mt-2 text-center text-base text-gray-600">
Don't have any account?
<Link
href="/signup"
className="font-medium text-primary transition-all duration-200 hover:underline"
>
Sign Up
</Link>
</p>
{error && <p className="text-red-600 mt-8 text-center">{error}</p>}
<form onSubmit={login} className="mt-8">
<div className="space-y-5">
<div>
<label htmlFor="email" className="text-base font-medium text-gray-900">
Email address
</label>
<div className="mt-2">
<input
className="flex h-10 w-full rounded-md border border-gray-300 bg-transparent px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-1 focus:ring-gray-400 focus:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50"
type="email"
value={formData.email}
onChange={(e) =>
setFormData((prev) => ({ ...prev, email: e.target.value }))
}
placeholder="Email"
id="email"
required
/>
</div>
</div>
<div>
<div className="flex items-center justify-between">
<label htmlFor="password" className="text-base font-medium text-gray-900">
Password
</label>
</div>
<div className="mt-2">
<input
className="flex h-10 w-full rounded-md border border-gray-300 bg-transparent px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-1 focus:ring-gray-400 focus:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50"
type="password"
placeholder="Password"
value={formData.password}
onChange={(e) =>
setFormData((prev) => ({
...prev,
password: e.target.value,
}))
}
id="password"
required
/>
</div>
</div>
<div>
<button
type="submit"
className="inline-flex w-full items-center justify-center rounded-md bg-primary px-3.5 py-2.5 font-semibold leading-7 text-white hover:bg-primary/80"
>
Sign in
</button>
</div>
</div>
</form>
</div>
</div>
);
}
export default Login;