Refactor authentication architecture to eliminate dual auth complexity
This major refactor consolidates the authentication system to use a single source of truth, eliminating timing issues and architectural complexity that was causing chat and payment functionality problems. Key Changes: • Remove old global useAuth composable and replace with useAuthService wrapper • Update all 25+ files to use consistent auth pattern via dependency injection • Eliminate dual auth detection workarounds from services (ChatService, PaymentService, etc.) • Fix TypeScript errors and add proper Uint8Array conversion for Nostr private keys • Consolidate auth state management to AuthService as single source of truth Benefits: • Resolves chat peer loading and message subscription timing issues • Fixes wallet detection problems for Lightning payments • Eliminates race conditions between global and injected auth • Maintains API compatibility while improving architecture • Reduces code complexity and improves maintainability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
5633aa154b
commit
4feb5459cc
27 changed files with 210 additions and 518 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { ref, computed, onUnmounted, onMounted } from 'vue'
|
||||
import { ref, computed, onUnmounted } from 'vue'
|
||||
import { purchaseTicket, checkPaymentStatus } from '@/lib/api/events'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useAuth } from '@/composables/useAuthService'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { useAsyncOperation } from '@/core/composables/useAsyncOperation'
|
||||
import { injectService, SERVICE_TOKENS } from '@/core/di-container'
|
||||
|
|
@ -24,9 +24,6 @@ export function useTicketPurchase() {
|
|||
const purchasedTicketId = ref<string | null>(null)
|
||||
const showTicketQR = ref(false)
|
||||
|
||||
// Wallet state (loaded asynchronously)
|
||||
const userWallets = ref<any[]>([])
|
||||
const hasWalletWithBalance = ref(false)
|
||||
|
||||
// Computed properties
|
||||
const canPurchase = computed(() => isAuthenticated.value && currentUser.value)
|
||||
|
|
@ -38,30 +35,10 @@ export function useTicketPurchase() {
|
|||
}
|
||||
})
|
||||
|
||||
// Delegate to PaymentService for processing status
|
||||
const isPayingWithWallet = computed(() => paymentService.isProcessingPayment.value) // computed ref
|
||||
|
||||
// Load wallets asynchronously
|
||||
async function loadWallets() {
|
||||
try {
|
||||
const wallets = await paymentService.getUserWalletsAsync()
|
||||
userWallets.value = wallets
|
||||
hasWalletWithBalance.value = await paymentService.hasWalletWithBalanceAsync()
|
||||
console.log('Loaded wallets for ticket purchase:', {
|
||||
count: wallets.length,
|
||||
hasBalance: hasWalletWithBalance.value
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Failed to load wallets:', error)
|
||||
userWallets.value = []
|
||||
hasWalletWithBalance.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Load wallets on mount
|
||||
onMounted(() => {
|
||||
loadWallets()
|
||||
})
|
||||
// Delegate to PaymentService
|
||||
const userWallets = computed(() => paymentService.userWallets)
|
||||
const hasWalletWithBalance = computed(() => paymentService.hasWalletWithBalance)
|
||||
const isPayingWithWallet = computed(() => paymentService.isProcessingPayment.value)
|
||||
|
||||
// Generate QR code for Lightning payment - delegate to PaymentService
|
||||
async function generateQRCode(bolt11: string) {
|
||||
|
|
@ -241,7 +218,6 @@ export function useTicketPurchase() {
|
|||
handleOpenLightningWallet,
|
||||
resetPaymentState,
|
||||
cleanup,
|
||||
generateTicketQRCode,
|
||||
loadWallets
|
||||
generateTicketQRCode
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ import { computed } from 'vue'
|
|||
import { useAsyncState } from '@vueuse/core'
|
||||
import type { Ticket } from '@/lib/types/event'
|
||||
import { fetchUserTickets } from '@/lib/api/events'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useAuth } from '@/composables/useAuthService'
|
||||
|
||||
interface GroupedTickets {
|
||||
eventId: string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue