diff --git a/src/pages/InvitePage.tsx b/src/pages/InvitePage.tsx index c0bdfbd..9193e17 100644 --- a/src/pages/InvitePage.tsx +++ b/src/pages/InvitePage.tsx @@ -25,6 +25,7 @@ import React, { useState, useEffect } from 'react'; import { useParams, useNavigate, Link } from 'react-router-dom'; import { useInvitations, type InvitationValidation } from '../hooks/useInvitations'; import api from '../api'; +import { getUserDataCache } from '../utils/userCache'; import { FaCheckCircle, FaTimesCircle, FaSpinner, FaSignInAlt, FaUserPlus } from 'react-icons/fa'; import styles from './InvitePage.module.css'; @@ -45,6 +46,7 @@ export const InvitePage: React.FC = () => { const [accepting, setAccepting] = useState(false); const [success, setSuccess] = useState(false); const [error, setError] = useState(null); + const [userMismatch, setUserMismatch] = useState(false); const [userExists, setUserExists] = useState(null); // Validate token on mount @@ -84,6 +86,14 @@ export const InvitePage: React.FC = () => { } } + if (result.valid && isAuthenticated && result.targetUsername) { + const cachedUser = getUserDataCache(); + if (cachedUser?.username && cachedUser.username.toLowerCase() !== result.targetUsername.toLowerCase()) { + localStorage.removeItem(PENDING_INVITATION_KEY); + setUserMismatch(true); + } + } + setValidating(false); }; @@ -190,6 +200,29 @@ export const InvitePage: React.FC = () => { ); } + // Authenticated but invitation is for a different user + if (userMismatch && validation?.valid) { + const cachedUser = getUserDataCache(); + return ( +
+
+
+ +

Falsche Anmeldung

+

+ Diese Einladung ist für {validation.targetUsername} bestimmt. + Sie sind als {cachedUser?.username || 'anderer Benutzer'} angemeldet. +

+

Bitte melden Sie sich ab und mit dem richtigen Konto wieder an.

+ + Zum Dashboard + +
+
+
+ ); + } + // Already authenticated - show accept button const isFeatureInvite = !!validation.featureInstanceId; const introText = isFeatureInvite