Unify auth: bridge auth store and Nostr account on every login path

The app had two disconnected auth systems:
- Auth store (useAuth): controls isAuthenticated, subscription, My List
- Account manager (useAccounts): controls isNostrLoggedIn, comments

Previously each login path only populated one system:
- Persona login → Nostr only (no subscription/My List)
- AuthModal Nostr → Auth store only (no commenting)
- Extension login → Nostr only (no subscription/My List)

Now every login path bridges both systems:
- Persona/extension login also calls auth store loginWithNostr
- AuthModal Nostr login also registers extension in accountManager
- Logout already cleared both (no change needed)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Dorian
2026-02-12 13:20:35 +00:00
parent 32e1751df3
commit dcb419d67a
2 changed files with 29 additions and 2 deletions

View File

@@ -213,6 +213,7 @@ import { ref, computed, onMounted, onUnmounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useAuth } from '../composables/useAuth'
import { useAccounts } from '../composables/useAccounts'
import { accountManager } from '../lib/accounts'
import { useContentDiscovery } from '../composables/useContentDiscovery'
type Persona = { name: string; nsec: string; pubkey: string }
@@ -237,7 +238,7 @@ const emit = defineEmits<Emits>()
const router = useRouter()
const route = useRoute()
const { user, isAuthenticated, logout: appLogout } = useAuth()
const { user, isAuthenticated, loginWithNostr: appLoginWithNostr, logout: appLogout } = useAuth()
const {
isLoggedIn: nostrLoggedIn,
activePubkey: nostrActivePubkey,
@@ -347,11 +348,28 @@ function navigateTo(path: string) {
async function handlePersonaLogin(persona: Persona) {
personaMenuOpen.value = false
// Set up Nostr account (for commenting/reactions)
await loginWithPersona(persona)
// Also populate auth store (for subscription/My List access)
try {
await appLoginWithNostr(persona.pubkey, 'persona', {})
} catch {
// Auth store mock login — non-critical if it fails
}
}
async function handleExtensionLogin() {
// Set up Nostr account (for commenting/reactions)
await loginWithExtension()
// Also populate auth store (for subscription/My List access)
try {
const pubkey = accountManager.active?.pubkey
if (pubkey) {
await appLoginWithNostr(pubkey, 'extension', {})
}
} catch {
// Auth store mock login — non-critical if it fails
}
}
async function handleLogout() {