Update src/auth/Login.tsx
Browse files- src/auth/Login.tsx +5 -20
src/auth/Login.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import { useState } from "react";
|
| 2 |
import api from "../api";
|
| 3 |
-
import {
|
| 4 |
import { useNavigate } from "react-router-dom";
|
| 5 |
|
| 6 |
export default function Login() {
|
|
@@ -12,7 +12,7 @@ export default function Login() {
|
|
| 12 |
async function submit() {
|
| 13 |
setLoading(true);
|
| 14 |
const r = await api.post("/auth/login", { email, password });
|
| 15 |
-
|
| 16 |
nav("/");
|
| 17 |
}
|
| 18 |
|
|
@@ -20,24 +20,9 @@ export default function Login() {
|
|
| 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 |
-
|
| 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>
|
|
|
|
| 1 |
import { useState } from "react";
|
| 2 |
import api from "../api";
|
| 3 |
+
import { setAccessToken } from "./auth";
|
| 4 |
import { useNavigate } from "react-router-dom";
|
| 5 |
|
| 6 |
export default function Login() {
|
|
|
|
| 12 |
async function submit() {
|
| 13 |
setLoading(true);
|
| 14 |
const r = await api.post("/auth/login", { email, password });
|
| 15 |
+
setAccessToken(r.data.accessToken);
|
| 16 |
nav("/");
|
| 17 |
}
|
| 18 |
|
|
|
|
| 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 |
+
<input className="w-full p-2 rounded bg-zinc-800" placeholder="Email" onChange={e=>setEmail(e.target.value)} />
|
| 24 |
+
<input type="password" className="w-full p-2 rounded bg-zinc-800" placeholder="Password" onChange={e=>setPassword(e.target.value)} />
|
| 25 |
+
<button onClick={submit} disabled={loading} className="btn w-full bg-blue-600 hover:bg-blue-500">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
{loading ? "..." : "Login"}
|
| 27 |
</button>
|
| 28 |
</div>
|