From a35272ff8e36c94a2f0784c8455f583296149809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 12 Jul 2026 02:16:42 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20login=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One form that switches between login and register modes. On success the auth resource is already mutated from the server response, so navigation lands on a fully hydrated app with no extra fetch. --- src/pages/Login.tsx | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/pages/Login.tsx diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx new file mode 100644 index 0000000..33e2c7e --- /dev/null +++ b/src/pages/Login.tsx @@ -0,0 +1,86 @@ +// Login / register, one form with a mode switch. On success the auth resource +// is already mutated, so navigation lands on a fully hydrated app. + +import { Navigate, useNavigate } from "@solidjs/router"; +import { Show, createSignal } from "solid-js"; +import { ErrorLine } from "../components/Feedback"; +import { IconPlane } from "../components/Icons"; +import { createAction } from "../lib/action"; +import { useAuth } from "../lib/auth"; +import { LIMITS } from "../lib/types"; + +export default function Login() { + const { user, login, register } = useAuth(); + const navigate = useNavigate(); + const [mode, setMode] = createSignal<"login" | "register">("login"); + + const submit = createAction(async (form: HTMLFormElement) => { + const data = new FormData(form); + const credentials = { + username: String(data.get("username")), + password: String(data.get("password")), + }; + await (mode() === "login" ? login(credentials) : register(credentials)); + navigate("/", { replace: true }); + }); + + const switchMode = () => { + setMode((m) => (m === "login" ? "register" : "login")); + submit.clearError(); + }; + + return ( + }> +
+
{ + e.preventDefault(); + void submit.run(e.currentTarget); + }} + > +
+ + + +

Hezarfen

+

+ {mode() === "login" + ? "Welcome back — log in to continue." + : "Create an account to get started."} +

+
+ + + + + + +
+
+ ); +}