Skip to content

Commit a6e556e

Browse files
committed
fix(frontend): hide SelfCareAiSection for anonymous users
/self-care e' una pagina pubblica, ma SelfCareAiSection montava useAiContext che chiama GET /api/ai/status ([Authorize]). Per utenti non autenticati il 401 faceva scattare l'interceptor axios -> redirect forzato a /login, rompendo i test e2e public-pages e a11y. Ora la sezione AI viene renderizzata solo dopo che AuthContext conferma un utente loggato.
1 parent 4b48218 commit a6e556e

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

frontend/src/components/SelfCareAiSection.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@ import { useTranslation } from 'react-i18next';
33
import AiAssistPanel from './AiAssistPanel';
44
import { checkInReflection } from '../api/ai';
55
import { useAiContext } from '../hooks/useAiContext';
6+
import { useAuth } from '../auth/AuthContext';
67

8+
// /self-care è una pagina pubblica ma `/api/ai/status` è `[Authorize]`:
9+
// se montassimo SelfCareAiSectionInner per gli anonimi, l'interceptor
10+
// axios reagirebbe al 401 con un redirect forzato a /login. Mostriamo
11+
// la sezione AI solo dopo che AuthContext ha confermato un utente.
712
export default function SelfCareAiSection() {
13+
const { user, loading } = useAuth();
14+
if (loading || !user) return null;
15+
return <SelfCareAiSectionInner />;
16+
}
17+
18+
function SelfCareAiSectionInner() {
819
const { t } = useTranslation();
920
const [days, setDays] = useState(14);
1021
const { systemAvailable, loading } = useAiContext();

0 commit comments

Comments
 (0)