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:
@@ -213,6 +213,7 @@ import { ref, computed, onMounted, onUnmounted } from 'vue'
|
|||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { useAuth } from '../composables/useAuth'
|
import { useAuth } from '../composables/useAuth'
|
||||||
import { useAccounts } from '../composables/useAccounts'
|
import { useAccounts } from '../composables/useAccounts'
|
||||||
|
import { accountManager } from '../lib/accounts'
|
||||||
import { useContentDiscovery } from '../composables/useContentDiscovery'
|
import { useContentDiscovery } from '../composables/useContentDiscovery'
|
||||||
|
|
||||||
type Persona = { name: string; nsec: string; pubkey: string }
|
type Persona = { name: string; nsec: string; pubkey: string }
|
||||||
@@ -237,7 +238,7 @@ const emit = defineEmits<Emits>()
|
|||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { user, isAuthenticated, logout: appLogout } = useAuth()
|
const { user, isAuthenticated, loginWithNostr: appLoginWithNostr, logout: appLogout } = useAuth()
|
||||||
const {
|
const {
|
||||||
isLoggedIn: nostrLoggedIn,
|
isLoggedIn: nostrLoggedIn,
|
||||||
activePubkey: nostrActivePubkey,
|
activePubkey: nostrActivePubkey,
|
||||||
@@ -347,11 +348,28 @@ function navigateTo(path: string) {
|
|||||||
|
|
||||||
async function handlePersonaLogin(persona: Persona) {
|
async function handlePersonaLogin(persona: Persona) {
|
||||||
personaMenuOpen.value = false
|
personaMenuOpen.value = false
|
||||||
|
// Set up Nostr account (for commenting/reactions)
|
||||||
await loginWithPersona(persona)
|
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() {
|
async function handleExtensionLogin() {
|
||||||
|
// Set up Nostr account (for commenting/reactions)
|
||||||
await loginWithExtension()
|
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() {
|
async function handleLogout() {
|
||||||
|
|||||||
@@ -122,6 +122,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { useAuth } from '../composables/useAuth'
|
import { useAuth } from '../composables/useAuth'
|
||||||
|
import { useAccounts } from '../composables/useAccounts'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
@@ -140,6 +141,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
const emit = defineEmits<Emits>()
|
const emit = defineEmits<Emits>()
|
||||||
|
|
||||||
const { login, loginWithNostr, register, isLoading: authLoading } = useAuth()
|
const { login, loginWithNostr, register, isLoading: authLoading } = useAuth()
|
||||||
|
const { loginWithExtension } = useAccounts()
|
||||||
|
|
||||||
const mode = ref<'login' | 'register' | 'forgot'>(props.defaultMode)
|
const mode = ref<'login' | 'register' | 'forgot'>(props.defaultMode)
|
||||||
const formData = ref({
|
const formData = ref({
|
||||||
@@ -206,9 +208,16 @@ async function handleNostrLogin() {
|
|||||||
// Sign event with extension
|
// Sign event with extension
|
||||||
const signedEvent = await window.nostr.signEvent(authEvent)
|
const signedEvent = await window.nostr.signEvent(authEvent)
|
||||||
|
|
||||||
// Create session with backend
|
// Create session with backend (auth store — subscription/My List)
|
||||||
await loginWithNostr(pubkey, signedEvent.sig, signedEvent)
|
await loginWithNostr(pubkey, signedEvent.sig, signedEvent)
|
||||||
|
|
||||||
|
// Also register extension account in accountManager (commenting/reactions)
|
||||||
|
try {
|
||||||
|
await loginWithExtension()
|
||||||
|
} catch {
|
||||||
|
// Non-critical — extension account already obtained pubkey above
|
||||||
|
}
|
||||||
|
|
||||||
emit('success')
|
emit('success')
|
||||||
closeModal()
|
closeModal()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
Reference in New Issue
Block a user