Twan07 commited on
Commit
f1d4f8d
·
verified ·
1 Parent(s): e92b14b

Create src/auth/Login.tsx

Browse files
Files changed (1) hide show
  1. src/auth/Login.tsx +46 -0
src/auth/Login.tsx ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from "react";
2
+ import api from "../api";
3
+ import { setTokens } from "./auth";
4
+ import { useNavigate } from "react-router-dom";
5
+
6
+ export default function Login() {
7
+ const [email, setEmail] = useState("");
8
+ const [password, setPassword] = useState("");
9
+ const [loading, setLoading] = useState(false);
10
+ const nav = useNavigate();
11
+
12
+ async function submit() {
13
+ setLoading(true);
14
+ const r = await api.post("/auth/login", { email, password });
15
+ setTokens(r.data.accessToken);
16
+ nav("/");
17
+ }
18
+
19
+ return (
20
+ <div className="min-h-screen flex items-center justify-center">
21
+ <div className="bg-zinc-900 p-6 rounded-xl w-80 space-y-4">
22
+ <h1 className="text-xl font-bold">Login</h1>
23
+
24
+ <input
25
+ className="w-full p-2 rounded bg-zinc-800"
26
+ placeholder="Email"
27
+ onChange={(e) => setEmail(e.target.value)}
28
+ />
29
+ <input
30
+ type="password"
31
+ className="w-full p-2 rounded bg-zinc-800"
32
+ placeholder="Password"
33
+ onChange={(e) => setPassword(e.target.value)}
34
+ />
35
+
36
+ <button
37
+ disabled={loading}
38
+ onClick={submit}
39
+ className="w-full bg-blue-600 p-2 rounded hover:bg-blue-500"
40
+ >
41
+ {loading ? "..." : "Login"}
42
+ </button>
43
+ </div>
44
+ </div>
45
+ );
46
+ }