feat: User-Management mit Token-basierter Authentifizierung
Backend: - UserRecord Model + Users-Tabelle in DB - AuthService: SHA256-Passwort-Hashing, Token-Verwaltung (ConcurrentDictionary) - AuthMiddleware: Schützt alle /api/-Routes (außer /api/auth/login) - AuthEndpoint: Login, Logout, Me - Default-User admin/admin wird automatisch erstellt Frontend: - Login-Page mit Formular (Enter-Key-Support) - Globaler Fetch-Interceptor: 401 → automatisch Login-Redirect - Auth-Check beim App-Start und bei Hash-Änderungen - Logout-Link im Dashboard-Header - Login-CSS: Zentrierte Login-Box
This commit is contained in:
1 parent
a1c54bf376
commit
9a59ae686d
13 files changed
+446
-3
No files matched your search
@@ -1,3 +1,44 @@
|
||||
// ── Global 401 Handler ──
|
||||
|
||||
(function() {
|
||||
var _origFetch = window.fetch;
|
||||
window.fetch = function(url, opts) {
|
||||
return _origFetch.apply(this, arguments).then(function(resp) {
|
||||
if (resp.status === 401 && typeof url === 'string' && !url.includes('/api/auth/')) {
|
||||
if (typeof currentPage !== 'undefined' && currentPage !== 'login') {
|
||||
navigateTo('login');
|
||||
}
|
||||
}
|
||||
return resp;
|
||||
});
|
||||
};
|
||||
})();
|
||||
|
||||
// ── Auth API ──
|
||||
|
||||
async function apiLogin(username, password) {
|
||||
const resp = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
if (!resp.ok) {
|
||||
const err = await resp.json();
|
||||
throw new Error(err.error || 'Login failed');
|
||||
}
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiLogout() {
|
||||
await fetch('/api/auth/logout', { method: 'POST' });
|
||||
}
|
||||
|
||||
async function apiMe() {
|
||||
const resp = await fetch('/api/auth/me');
|
||||
if (!resp.ok) return null;
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
// ── API Calls ──
|
||||
|
||||
async function apiChat(messages, sessionId, signal) {
|
||||
|
||||
Reference in new issue
Block a user