aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/src/routes/Login.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/routes/Login.tsx')
-rw-r--r--frontend/src/routes/Login.tsx21
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}/`);
+};