From f0d888729b999cdf814aa2308d56e1471aa6d6e2 Mon Sep 17 00:00:00 2001 From: t0ng7u Date: Wed, 25 Jun 2025 23:13:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(auth):=20restore=20proper=20?= =?UTF-8?q?state=20&=20context=20destructuring=20in=20Login-=20and=20Regis?= =?UTF-8?q?ter-forms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why Clicking the “Continue” button on the login page no longer triggered the submission logic. The issue was introduced when `useState`/`useContext` hooks were destructured incorrectly, breaking the setter reference and omitting required values. What’s changed • **LoginForm.js** – Re-added setter in `useSearchParams` (`[searchParams, setSearchParams]`). – Corrected order of destructuring for `inputs` so `username`/`password` are available after hooks. – Switched `useContext` to `[userState, userDispatch]` for consistency. • **RegisterForm.js** – Adopted `[userState, userDispatch]` from `UserContext` to mirror LoginForm and retain full state access. Outcome Login button now successfully invokes `handleSubmit`, and both auth components have consistent, fully-featured hook destructuring, preventing runtime errors and ensuring future state usage is straightforward. --- web/src/components/auth/LoginForm.js | 6 +++--- web/src/components/auth/RegisterForm.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/components/auth/LoginForm.js b/web/src/components/auth/LoginForm.js index 988be4a2..7bd51dba 100644 --- a/web/src/components/auth/LoginForm.js +++ b/web/src/components/auth/LoginForm.js @@ -42,9 +42,9 @@ const LoginForm = () => { wechat_verification_code: '', }); const { username, password } = inputs; - const [searchParams] = useSearchParams(); - const [setSubmitted] = useState(false); - const [userDispatch] = useContext(UserContext); + const [searchParams, setSearchParams] = useSearchParams(); + const [submitted, setSubmitted] = useState(false); + const [userState, userDispatch] = useContext(UserContext); const [turnstileEnabled, setTurnstileEnabled] = useState(false); const [turnstileSiteKey, setTurnstileSiteKey] = useState(''); const [turnstileToken, setTurnstileToken] = useState(''); diff --git a/web/src/components/auth/RegisterForm.js b/web/src/components/auth/RegisterForm.js index 00cc98fc..a3a5e0b4 100644 --- a/web/src/components/auth/RegisterForm.js +++ b/web/src/components/auth/RegisterForm.js @@ -46,7 +46,7 @@ const RegisterForm = () => { wechat_verification_code: '', }); const { username, password, password2 } = inputs; - const [userDispatch] = useContext(UserContext); + const [userState, userDispatch] = useContext(UserContext); const [turnstileEnabled, setTurnstileEnabled] = useState(false); const [turnstileSiteKey, setTurnstileSiteKey] = useState(''); const [turnstileToken, setTurnstileToken] = useState('');