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:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user