🐛 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.
This commit is contained in:
t0ng7u
2025-06-25 23:13:55 +08:00
parent 6d7d4292ef
commit f0d888729b
2 changed files with 4 additions and 4 deletions

View File

@@ -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('');

View File

@@ -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('');