Enhance CheckoutPage with Nostr integration for order placement

- Import and utilize the Nostr store to retrieve the user's public key for order placement.
- Implement debug logging to track authentication state and public key availability.
- Ensure that the order placement process checks for a valid Nostr public key, improving user feedback and error handling during the checkout process.
This commit is contained in:
padreug 2025-09-05 06:08:16 +02:00
parent 7c439361b7
commit c7fcd51990

View file

@ -272,6 +272,7 @@
import { ref, computed, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { useMarketStore } from '@/stores/market'
import { useNostrStore } from '@/stores/nostr'
import { injectService, SERVICE_TOKENS } from '@/core/di-container'
import {
Card,
@ -291,6 +292,7 @@ import {
const route = useRoute()
const marketStore = useMarketStore()
const nostrStore = useNostrStore()
const authService = injectService(SERVICE_TOKENS.AUTH_SERVICE) as any
// State
@ -410,14 +412,29 @@ const placeOrder = async () => {
if (!currentStall.value) {
throw new Error('Stall information not available')
}
if (!authService.isAuthenticated.value || !authService.user.value?.pubkey) {
// Debug logging to understand auth state
console.log('Auth check:', {
isAuthenticated: authService.isAuthenticated.value,
user: authService.user.value,
hasPubkey: !!authService.user.value?.pubkey,
nostrPubkey: nostrStore.account?.pubkey
})
// Get pubkey from auth service or fallback to nostr store
const userPubkey = authService.user.value?.pubkey || nostrStore.account?.pubkey
if (!authService.isAuthenticated.value) {
throw new Error('You must be logged in to place an order')
}
if (!userPubkey) {
throw new Error('No Nostr public key found. Please ensure your Nostr identity is configured.')
}
// Create the order using the market store's order placement functionality
const orderData = {
stallId: stallId.value,
buyerPubkey: authService.user.value?.pubkey || '',
buyerPubkey: userPubkey,
sellerPubkey: currentStall.value.pubkey,
status: 'pending' as const,
items: checkoutCart.value.products.map(item => ({