diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-22 04:36:45 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-22 04:36:53 +0900 |
| commit | a4685927a1f7fe8374a567ee74cc62aad639f4c3 (patch) | |
| tree | 1eaf5845965c4d5d2db4faf9582c17444a762ffd /frontend/src/routes/Login.tsx | |
| parent | 2512da7ca57dc4c52900417a50daf4f6f2f74054 (diff) | |
| download | iosdc-japan-2024-albatross-a4685927a1f7fe8374a567ee74cc62aad639f4c3.tar.gz iosdc-japan-2024-albatross-a4685927a1f7fe8374a567ee74cc62aad639f4c3.tar.zst iosdc-japan-2024-albatross-a4685927a1f7fe8374a567ee74cc62aad639f4c3.zip | |
user login
Diffstat (limited to 'frontend/src/routes/Login.tsx')
| -rw-r--r-- | frontend/src/routes/Login.tsx | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/frontend/src/routes/Login.tsx b/frontend/src/routes/Login.tsx index 1945abe..f3fa00e 100644 --- a/frontend/src/routes/Login.tsx +++ b/frontend/src/routes/Login.tsx @@ -1,4 +1,4 @@ -import { Form } from "react-router-dom"; +import { redirect, Form, ActionFunctionArgs } from "react-router-dom"; export default function Login() { return ( @@ -17,3 +17,22 @@ export default function Login() { </div> ); }; + +export async function loginAction({ request }: ActionFunctionArgs) { + const formData = await request.formData(); + const username = formData.get("username"); + const password = formData.get("password"); + + const res = await fetch("/api/login", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ username, password }), + }); + if (!res.ok) { + throw res; + } + const { userId } = await res.json(); + return redirect(`/users/${userId}/`); +}; |
