Fix: friends.js Auth-Guards für nicht eingeloggte User

This commit is contained in:
rene 2026-04-16 22:48:44 +02:00
parent 44fcb9bc16
commit 21e50c6c7b
4 changed files with 22 additions and 8 deletions

View file

@ -22,8 +22,8 @@
<!-- CSS: Reihenfolge ist wichtig — ?v= zwingt Browser zur Neuladung -->
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/layout.css?v=80">
<link rel="stylesheet" href="/css/components.css?v=80">
<link rel="stylesheet" href="/css/layout.css?v=81">
<link rel="stylesheet" href="/css/components.css?v=81">
</head>
<body>
@ -269,9 +269,9 @@
<div id="modal-container"></div>
<!-- JS: Reihenfolge ist wichtig — erst Basis, dann Features -->
<script src="/js/api.js?v=80"></script>
<script src="/js/ui.js?v=80"></script>
<script src="/js/app.js?v=80"></script>
<script src="/js/api.js?v=81"></script>
<script src="/js/ui.js?v=81"></script>
<script src="/js/app.js?v=81"></script>
<!-- Feature-Seiten werden lazy geladen -->

View file

@ -3,7 +3,7 @@
Router, State-Management, Navigation, Initialisierung.
============================================================ */
const APP_VER = '80'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VER = '81'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const App = (() => {

View file

@ -22,6 +22,16 @@ window.Page_friends = (() => {
// HAUPT-RENDER
// ----------------------------------------------------------
function _render(prefill = null) {
if (!_appState.user) {
_container.innerHTML = UI.emptyState({
icon: UI.icon('users'),
title: 'Anmelden erforderlich',
text: 'Melde dich an, um Freunde zu finden und Anfragen zu verwalten.',
action: `<button class="btn btn-primary" onclick="App.navigate('settings')">Anmelden</button>`,
});
return;
}
const myName = _appState?.user?.name || '';
const myLink = `${location.origin}/#friends?suche=${encodeURIComponent(myName)}`;
@ -147,13 +157,14 @@ window.Page_friends = (() => {
// DATEN LADEN
// ----------------------------------------------------------
async function _loadFriends() {
if (!_appState.user) return;
try {
const data = await API.friends.list();
_renderIncoming(data.incoming || []);
_renderOutgoing(data.outgoing || []);
_renderFriends(data.friends || []);
_updateBadge((data.incoming || []).length);
} catch { /* 401 wird vom Auth-Guard abgefangen */ }
} catch { /* silent — 401 bei abgemeldeter Session */ }
}
function _updateBadge(count) {
@ -413,6 +424,7 @@ window.Page_friends = (() => {
// SUCHE
// ----------------------------------------------------------
async function _doSearch(q) {
if (!_appState.user) return;
const el = _container.querySelector('#fr-search-results');
try {
const results = await API.friends.search(q);
@ -462,6 +474,7 @@ window.Page_friends = (() => {
// AKTIONEN
// ----------------------------------------------------------
async function _sendRequest(userId, btn) {
if (!_appState.user) { App.navigate('settings'); return; }
btn.disabled = true;
btn.innerHTML = `<svg class="ph-icon"><use href="/icons/phosphor.svg#spinner"></use></svg>`;
try {
@ -514,6 +527,7 @@ window.Page_friends = (() => {
}
async function _openChat(userId) {
if (!_appState.user) { App.navigate('settings'); return; }
try {
const { conversation_id } = await API.chat.start(userId);
App.navigate('chat', true, { conversation_id });

View file

@ -3,7 +3,7 @@
Offline-Cache + Push Notifications + Tile-Cache
============================================================ */
const CACHE_VERSION = 'by-v104';
const CACHE_VERSION = 'by-v105';
const CACHE_STATIC = `${CACHE_VERSION}-static`;
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten