Login mit Admin Admin login bis zum Dashboard

erfolgreich
This commit is contained in:
Nirodan
2025-06-14 18:57:43 +02:00
parent a3e521e458
commit 86308925ea
5 changed files with 48 additions and 9 deletions
+12 -4
View File
@@ -1,4 +1,3 @@
// src/components/LoginForm.jsx
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import axios from '../services/api';
@@ -10,7 +9,7 @@ function LoginForm() {
const login = async () => {
try {
const res = await axios.post('/login', { username, password });
const res = await axios.post('/login', { username, password }); // ruft POST /api/login auf
localStorage.setItem('token', res.data.token);
localStorage.setItem('role', res.data.role);
navigate('/');
@@ -22,8 +21,17 @@ function LoginForm() {
return (
<div>
<h2>Login</h2>
<input value={username} onChange={e => setUsername(e.target.value)} placeholder="Benutzername" />
<input type="password" value={password} onChange={e => setPassword(e.target.value)} placeholder="Passwort" />
<input
value={username}
onChange={e => setUsername(e.target.value)}
placeholder="Benutzername"
/>
<input
type="password"
value={password}
onChange={e => setPassword(e.target.value)}
placeholder="Passwort"
/>
<button onClick={login}>Anmelden</button>
</div>
);