Enhance market DM decryption process with improved authentication checks

- Introduced checks for both injected auth service and global auth composable to retrieve user private and public keys.
- Enhanced logging to provide clearer feedback on authentication status during DM decryption attempts.
- Improved error handling for cases where user keys are unavailable, ensuring better user guidance.

These changes strengthen the authentication flow and improve the reliability of market-related direct messages.
This commit is contained in:
padreug 2025-09-06 23:52:30 +02:00
parent d3ee19f56f
commit c7e11a7c01

View file

@ -5,6 +5,7 @@ import { config } from '@/lib/config'
import { nostrmarketService } from '../services/nostrmarketService' import { nostrmarketService } from '../services/nostrmarketService'
import { nip04 } from 'nostr-tools' import { nip04 } from 'nostr-tools'
import { useAsyncOperation } from '@/core/composables/useAsyncOperation' import { useAsyncOperation } from '@/core/composables/useAsyncOperation'
import { auth } from '@/composables/useAuth'
// Nostr event kinds for market functionality // Nostr event kinds for market functionality
const MARKET_EVENT_KINDS = { const MARKET_EVENT_KINDS = {
@ -384,14 +385,29 @@ export function useMarket() {
try { try {
console.log('🔔 Received order-related DM:', event.id, 'from:', event.pubkey.slice(0, 8)) console.log('🔔 Received order-related DM:', event.id, 'from:', event.pubkey.slice(0, 8))
const userPrivkey = authService.user.value?.prvkey // Check both injected auth service AND global auth composable
const hasAuthService = authService.user.value?.prvkey
const hasGlobalAuth = auth.currentUser.value?.prvkey
if (!userPrivkey) { const userPrivkey = hasAuthService ? authService.user.value.prvkey : auth.currentUser.value?.prvkey
const userPubkey = hasAuthService ? authService.user.value.pubkey : auth.currentUser.value?.pubkey
if (!userPrivkey || !userPubkey) {
console.warn('Cannot decrypt DM: no user private key available', { console.warn('Cannot decrypt DM: no user private key available', {
authServicePrivkey: !!authService.user.value?.prvkey hasAuthService: !!hasAuthService,
hasGlobalAuth: !!hasGlobalAuth,
authServicePrivkey: !!authService.user.value?.prvkey,
globalAuthPrivkey: !!auth.currentUser.value?.prvkey
}) })
return return
} }
console.log('🔐 Market DM decryption auth check:', {
hasAuthService: !!hasAuthService,
hasGlobalAuth: !!hasGlobalAuth,
usingAuthService: !!hasAuthService,
userPubkey: userPubkey.substring(0, 10) + '...'
})
console.log('🔓 Attempting to decrypt DM with private key available') console.log('🔓 Attempting to decrypt DM with private key available')