fix(web): validate question input before divination and fix logout flow

- Add validation for question text in ManualDivinationPage and AutoDivinationPage
- Fix logout flow to call backend API before clearing local auth
- Show error message when question is empty before starting interpretation
This commit is contained in:
zl-q
2026-05-11 20:07:36 +08:00
parent 3cc5999383
commit 2b8984edbc
3 changed files with 15 additions and 4 deletions
@@ -422,6 +422,10 @@ export default function AutoDivinationPage({ locale, divination: d }: Props) {
const handleSubmit = () => {
if (!done) return;
if (!question.trim()) {
setErrorMessage(locale === 'en' ? 'Please enter your question before starting the interpretation.' : '请输入您要占卜的问题后再开始解卦。');
return;
}
setShowConfirm(true);
};
@@ -440,6 +440,10 @@ export default function ManualDivinationPage({ locale, divination: d }: Props) {
const showNextGuide = () => setGuideStep((step) => (step === null ? 0 : Math.min(step + 1, text.guideSteps.length - 1)));
const handleSubmit = () => {
if (!question.trim()) {
setErrorMessage(locale === 'en' ? 'Please enter your question before starting the interpretation.' : '请输入您要占卜的问题后再开始解卦。');
return;
}
setShowConfirm(true);
};
+7 -4
View File
@@ -21,11 +21,14 @@ export default function SettingsPage({ locale, settings: s }: Props) {
if (!confirm(s.logoutConfirm)) return;
setLogoutLoading(true);
// Clear local auth immediately and redirect
try {
// Call backend logout first (needs auth)
await logout();
} catch {
// Ignore logout API errors
}
// Clear local auth and redirect
clearAuth();
// Fire backend logout in background (don't wait)
logout().catch(() => {});
// Redirect to login
redirectToLogin();
};