From ca9112ebc0f8c02c87d583d592185957520b7d4c Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 21 Mar 2026 10:32:24 +0100 Subject: [PATCH] fix: email verification auto-login and user experience MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AuthContext: - Added setAuthFromToken() for direct token/profile set - Used for email verification auto-login (no /login request) - Properly initializes session with token and profile Verify.jsx: - Fixed auto-login: now uses setAuthFromToken() instead of login() - Added "already_verified" status for better UX - Auto-redirect to /login after 3s if already verified - Shows friendly message instead of error This fixes: - 422 Unprocessable Entity error during auto-login - Empty dashboard page after verification (now redirects correctly) - "Ungültiger Link" error on second click (now shows "bereits bestätigt") Co-Authored-By: Claude Opus 4.6 --- frontend/src/context/AuthContext.jsx | 14 +++++++- frontend/src/pages/Verify.jsx | 52 ++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/frontend/src/context/AuthContext.jsx b/frontend/src/context/AuthContext.jsx index ece4633..1bcd76a 100644 --- a/frontend/src/context/AuthContext.jsx +++ b/frontend/src/context/AuthContext.jsx @@ -86,6 +86,18 @@ export function AuthProvider({ children }) { return data } + const setAuthFromToken = (token, profile) => { + // Direct token/profile set (for email verification auto-login) + localStorage.setItem(TOKEN_KEY, token) + localStorage.setItem(PROFILE_KEY, profile.id) + setSession({ + token, + profile_id: profile.id, + role: profile.role || 'user', + profile + }) + } + const logout = async () => { const token = localStorage.getItem(TOKEN_KEY) if (token) { @@ -102,7 +114,7 @@ export function AuthProvider({ children }) { return ( navigate('/login'), 3000) + } // Check if token expired - if (errorMsg.includes('abgelaufen') || errorMsg.includes('expired')) { + else if (errorMsg.includes('abgelaufen') || errorMsg.includes('expired')) { setStatus('expired') setError(errorMsg) } else { @@ -54,7 +60,7 @@ export default function Verify() { } verify() - }, [token, login, navigate]) + }, [token, setAuthFromToken, navigate]) const handleResend = async () => { if (!email.trim()) { @@ -177,6 +183,40 @@ export default function Verify() { ) } + if (status === 'already_verified') { + return ( +
+
+
+

+ E-Mail bereits bestätigt +

+

+ Deine E-Mail-Adresse wurde bereits verifiziert. + Du kannst dich jetzt anmelden. +

+

+ Du wirst gleich zum Login weitergeleitet... +

+
+ + +
+ ) + } + if (status === 'error') { return (