feat: integrate content fetching on successful Amber login
- Added content store integration to re-fetch content after successful Amber login, ensuring backstage-published projects are merged into the active catalog. - Updated comments for clarity regarding the login flow and account registration timing. This change enhances the user experience by ensuring that the content is up-to-date immediately after authentication.
This commit is contained in:
@@ -49,6 +49,7 @@
|
|||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { useAuthStore } from './stores/auth'
|
import { useAuthStore } from './stores/auth'
|
||||||
|
import { useContentStore } from './stores/content'
|
||||||
import { useSearchSelectionStore } from './stores/searchSelection'
|
import { useSearchSelectionStore } from './stores/searchSelection'
|
||||||
import AppHeader from './components/AppHeader.vue'
|
import AppHeader from './components/AppHeader.vue'
|
||||||
import BackstageHeader from './components/BackstageHeader.vue'
|
import BackstageHeader from './components/BackstageHeader.vue'
|
||||||
@@ -62,6 +63,7 @@ import type { Content } from './types/content'
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
|
const contentStore = useContentStore()
|
||||||
const searchSelection = useSearchSelectionStore()
|
const searchSelection = useSearchSelectionStore()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,6 +95,12 @@ function handleAuthClose() {
|
|||||||
|
|
||||||
function handleAuthSuccess() {
|
function handleAuthSuccess() {
|
||||||
showAuthModal.value = false
|
showAuthModal.value = false
|
||||||
|
|
||||||
|
// Re-fetch content so backstage-published projects are merged
|
||||||
|
// into the active catalog (they require session tokens which
|
||||||
|
// are only available after login completes).
|
||||||
|
contentStore.fetchContent()
|
||||||
|
|
||||||
if (pendingRedirect.value) {
|
if (pendingRedirect.value) {
|
||||||
router.push(pendingRedirect.value)
|
router.push(pendingRedirect.value)
|
||||||
pendingRedirect.value = null
|
pendingRedirect.value = null
|
||||||
|
|||||||
@@ -493,15 +493,10 @@ async function handleAmberPubkeyRead() {
|
|||||||
const pubkey = await decodePubkeyFromClipboard(clipboardText)
|
const pubkey = await decodePubkeyFromClipboard(clipboardText)
|
||||||
amberPubkey.value = pubkey
|
amberPubkey.value = pubkey
|
||||||
|
|
||||||
// Register the Amber account in the account manager so the app
|
// NOTE: We do NOT register the Amber account in accountManager here.
|
||||||
// knows who is signing in (the signer is set but we won't call
|
// That happens in Phase 3 after backend login succeeds, to avoid a
|
||||||
// signEvent on it — we use intents + clipboard for that)
|
// split state where accountManager.active is set but authStore
|
||||||
const { AmberClipboardSigner, AmberClipboardAccount } = await import('../lib/accounts')
|
// isn't authenticated (which confuses guards and the UI).
|
||||||
const signer = new AmberClipboardSigner()
|
|
||||||
signer.pubkey = pubkey
|
|
||||||
const account = new AmberClipboardAccount(pubkey, signer)
|
|
||||||
accountManager.addAccount(account)
|
|
||||||
accountManager.setActive(account)
|
|
||||||
|
|
||||||
// Build the unsigned NIP-98 event that the backend expects.
|
// Build the unsigned NIP-98 event that the backend expects.
|
||||||
// Store it so Phase 3 can reuse the exact same event data
|
// Store it so Phase 3 can reuse the exact same event data
|
||||||
@@ -605,6 +600,19 @@ async function handleAmberSignComplete() {
|
|||||||
// Authenticate with the pre-signed NIP-98 header (bypasses signer.signEvent)
|
// Authenticate with the pre-signed NIP-98 header (bypasses signer.signEvent)
|
||||||
await loginWithNostr(pubkey, 'amber-nip55', {}, authHeader)
|
await loginWithNostr(pubkey, 'amber-nip55', {}, authHeader)
|
||||||
|
|
||||||
|
// Backend login succeeded — NOW register the Amber account in
|
||||||
|
// accountManager so the rest of the UI reflects the logged-in state.
|
||||||
|
try {
|
||||||
|
const { AmberClipboardSigner, AmberClipboardAccount } = await import('../lib/accounts')
|
||||||
|
const signer = new AmberClipboardSigner()
|
||||||
|
signer.pubkey = pubkey
|
||||||
|
const account = new AmberClipboardAccount(pubkey, signer)
|
||||||
|
accountManager.addAccount(account)
|
||||||
|
accountManager.setActive(account)
|
||||||
|
} catch (accountErr) {
|
||||||
|
console.warn('[Amber] Account registration after login:', accountErr)
|
||||||
|
}
|
||||||
|
|
||||||
amberPhase.value = 'idle'
|
amberPhase.value = 'idle'
|
||||||
amberPubkey.value = null
|
amberPubkey.value = null
|
||||||
amberUnsignedEvent.value = null
|
amberUnsignedEvent.value = null
|
||||||
|
|||||||
Reference in New Issue
Block a user