Browse Source

🐛 fix(auth): restore proper state & context destructuring in Login- and Register-forms

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.
t0ng7u 8 months ago
parent
commit
f0d888729b
2 changed files with 4 additions and 4 deletions
  1. 3 3
      web/src/components/auth/LoginForm.js
  2. 1 1
      web/src/components/auth/RegisterForm.js

+ 3 - 3
web/src/components/auth/LoginForm.js

@@ -42,9 +42,9 @@ const LoginForm = () => {
     wechat_verification_code: '',
     wechat_verification_code: '',
   });
   });
   const { username, password } = inputs;
   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 [turnstileEnabled, setTurnstileEnabled] = useState(false);
   const [turnstileSiteKey, setTurnstileSiteKey] = useState('');
   const [turnstileSiteKey, setTurnstileSiteKey] = useState('');
   const [turnstileToken, setTurnstileToken] = useState('');
   const [turnstileToken, setTurnstileToken] = useState('');

+ 1 - 1
web/src/components/auth/RegisterForm.js

@@ -46,7 +46,7 @@ const RegisterForm = () => {
     wechat_verification_code: '',
     wechat_verification_code: '',
   });
   });
   const { username, password, password2 } = inputs;
   const { username, password, password2 } = inputs;
-  const [userDispatch] = useContext(UserContext);
+  const [userState, userDispatch] = useContext(UserContext);
   const [turnstileEnabled, setTurnstileEnabled] = useState(false);
   const [turnstileEnabled, setTurnstileEnabled] = useState(false);
   const [turnstileSiteKey, setTurnstileSiteKey] = useState('');
   const [turnstileSiteKey, setTurnstileSiteKey] = useState('');
   const [turnstileToken, setTurnstileToken] = useState('');
   const [turnstileToken, setTurnstileToken] = useState('');