From d651fc3ff27b974155407ebaf6b407a12d1ad04f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 6 Aug 2026 16:30:37 +0000 Subject: [PATCH] feat(auth): LoginPage - fix credentials, fetch /auth/me after login --- frontend/src/pages/LoginPage.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/LoginPage.tsx b/frontend/src/pages/LoginPage.tsx index 4819cd1..575f720 100644 --- a/frontend/src/pages/LoginPage.tsx +++ b/frontend/src/pages/LoginPage.tsx @@ -1,10 +1,11 @@ import { useState } from 'react'; +import { setToken, setSessionUser } from '../lib/session'; -type Props = { onLogin: (token: string) => void }; +type Props = { onLogin: () => void }; export function LoginPage({ onLogin }: Props) { const [username, setUsername] = useState('admin'); - const [password, setPassword] = useState('admin123'); + const [password, setPassword] = useState('admin'); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); @@ -16,7 +17,7 @@ export function LoginPage({ onLogin }: Props) { const body = new URLSearchParams(); body.set('username', username); body.set('password', password); - const res = await fetch('/auth/token', { + const res = await fetch('/backend/auth/token', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: body.toString(), @@ -25,8 +26,13 @@ export function LoginPage({ onLogin }: Props) { const data = await res.json().catch(() => null); throw new Error(data?.detail ?? 'Login fallito'); } - const data = await res.json(); - onLogin(data.access_token); + const { access_token } = await res.json(); + setToken(access_token); + const meRes = await fetch('/backend/auth/me', { + headers: { Authorization: `Bearer ${access_token}` }, + }); + if (meRes.ok) setSessionUser(await meRes.json()); + onLogin(); } catch (err) { setError(err instanceof Error ? err.message : 'Login fallito'); } finally { @@ -49,7 +55,6 @@ export function LoginPage({ onLogin }: Props) { Password setPassword(e.target.value)} autoComplete="current-password" /> -

Credenziali demo: admin / admin123 oppure viewer / viewer123

{error &&

{error}

}