ADD: added initial page with login
This commit is contained in:
33
frontend/src/pages/LoginPage.tsx
Normal file
33
frontend/src/pages/LoginPage.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useState } from 'react';
|
||||
import { useAuth } from './AuthContext';
|
||||
import { login as apiLogin } from './api';
|
||||
|
||||
export default function LoginPage() {
|
||||
const { login } = useAuth();
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
try {
|
||||
const data = await apiLogin(email, password);
|
||||
console.log(data);
|
||||
// Token aus JWT extrahieren (hier: UserID im Token Payload)
|
||||
// Für Demo: Einfach Dummy UserID setzen, oder später JWT decode implementieren
|
||||
login(data.token, 'user-id-from-token');
|
||||
} catch {
|
||||
setError('Login fehlgeschlagen');
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="max-w-md mx-auto p-6">
|
||||
<h2 className="text-2xl mb-4">Login</h2>
|
||||
{error && <p className="text-red-600 mb-4">{error}</p>}
|
||||
<input type="email" placeholder="E-Mail" required value={email} onChange={e => setEmail(e.target.value)} className="border p-2 w-full mb-4" />
|
||||
<input type="password" placeholder="Passwort" required value={password} onChange={e => setPassword(e.target.value)} className="border p-2 w-full mb-4" />
|
||||
<button type="submit" className="bg-blue-600 text-white p-2 rounded w-full">Einloggen</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user