From a748f4607d971442ac1a7cf6f13a92e095ee4dd5 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 29 Apr 2026 11:48:04 +0200 Subject: [PATCH] refactor: improve email verification handling in components - Introduced a utility function to standardize email verification checks across EmailVerificationBanner and AccountSettingsPage. - Updated conditional logic to enhance clarity and maintainability regarding email verification status. - Ensured consistent treatment of various representations of email verification status in user profiles. --- frontend/src/components/EmailVerificationBanner.jsx | 8 +++++++- frontend/src/pages/AccountSettingsPage.jsx | 12 +++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/EmailVerificationBanner.jsx b/frontend/src/components/EmailVerificationBanner.jsx index 7a67259..b1409ad 100644 --- a/frontend/src/components/EmailVerificationBanner.jsx +++ b/frontend/src/components/EmailVerificationBanner.jsx @@ -1,6 +1,12 @@ import { useState } from 'react' import api from '../utils/api' +function isEmailVerifiedRow(p) { + if (!p) return false + const v = p.email_verified + return v === true || v === 't' || v === 1 || v === 'true' +} + /** * Hinweis + „Erneut senden“, wenn eingeloggt aber E-Mail noch nicht verifiziert (wie Mitai). */ @@ -9,7 +15,7 @@ export default function EmailVerificationBanner({ profile }) { const [success, setSuccess] = useState(false) const [error, setError] = useState('') - if (!profile?.email || profile.email_verified !== false) return null + if (!profile?.email || isEmailVerifiedRow(profile)) return null const handleResend = async () => { if (!profile.email) return diff --git a/frontend/src/pages/AccountSettingsPage.jsx b/frontend/src/pages/AccountSettingsPage.jsx index 0108f69..0edb2c0 100644 --- a/frontend/src/pages/AccountSettingsPage.jsx +++ b/frontend/src/pages/AccountSettingsPage.jsx @@ -22,7 +22,12 @@ function AccountSettingsPage() { setName(typeof user?.name === 'string' ? user.name : '') }, [user]) - const verified = !!user?.email_verified + /** API: boolean true / Legacy: fehlt oder false → als „nicht verifiziert“ behandeln */ + const emailExplicitlyVerified = + user?.email_verified === true || + user?.email_verified === 't' || + user?.email_verified === 1 || + user?.email_verified === 'true' const showOk = (text) => { setMessage(text) @@ -69,6 +74,7 @@ function AccountSettingsPage() { } } + const handleChangePassword = async (e) => { e.preventDefault() if (newPw1.length < 4) { showErr('Neues Passwort: mindestens 4 Zeichen.') @@ -133,7 +139,7 @@ function AccountSettingsPage() { E-Mail
{user?.email || '—'}{' '} - {verified ? ( + {emailExplicitlyVerified ? ( )} - {!verified && user?.email ? ( + {!emailExplicitlyVerified && user?.email ? (