This commit is contained in:
2026-09-13 14:19:37 +02:00
parent 466d3c4f28
commit 7a525494cf
6 changed files with 37 additions and 15 deletions
+24 -4
View File
@@ -765,6 +765,7 @@
* Explicitly log in as anonymous (generates identity if none, establishes session, syncs guest favs)
*/
async loginAsAnonymous() {
if (this._loginInProgress) return;
if (window.f0ckSession && window.f0ckSession.enable_anonymous_access === false) {
return;
}
@@ -780,14 +781,22 @@
return;
}
this._loginInProgress = true;
// Close the login modal immediately for visual feedback
const loginModal = document.getElementById('login-modal');
if (loginModal) loginModal.style.display = 'none';
try {
if (!this.pubkey) {
await this.generateIdentity(true);
} else {
await this.ensureSession(true, true);
await this.generateIdentity();
}
await this.ensureSession(true, true);
if (!this.isSessionReady) return;
if (!this.isSessionReady) {
this._loginInProgress = false;
return;
}
// Sync any guest favorites saved in localStorage to this anon account
if (window.f0ckGuestFavs && typeof window.f0ckGuestFavs.importToAccount === 'function') {
@@ -800,6 +809,7 @@
// Reload page to reflect authenticated anonymous session across navbar, comments, settings
window.location.reload();
} catch (err) {
this._loginInProgress = false;
console.error('[ANON_SSH] Login as anonymous failed:', err);
alert('Failed to log in as anonymous: ' + (err.message || err));
}
@@ -977,6 +987,16 @@
}
attachUIListeners() {
// Direct click handler for the modal login-as-anonymous button
const modalAnonBtn = document.getElementById('modal-login-as-anon-btn');
if (modalAnonBtn) {
modalAnonBtn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
this.loginAsAnonymous();
});
}
// Global click handler for Login as anonymous, Identity modal, & Logout
document.addEventListener('click', (e) => {
const identityTarget = e.target.closest('#nav-anon-identity-btn');