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,11 +1,11 @@
|
|||
<!-- eslint-disable vue/multi-word-component-names -->
|
||||
<script setup lang="ts">
|
||||
import { onUnmounted, watch } from 'vue'
|
||||
import { onUnmounted } from 'vue'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { useTicketPurchase } from '../composables/useTicketPurchase'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useAuth } from '@/composables/useAuthService'
|
||||
import { User, Wallet, CreditCard, Zap, Ticket } from 'lucide-vue-next'
|
||||
import { formatEventPrice, formatWalletBalance } from '@/lib/utils/formatting'
|
||||
|
||||
|
|
@ -44,8 +44,7 @@ const {
|
|||
cleanup,
|
||||
ticketQRCode,
|
||||
purchasedTicketId,
|
||||
showTicketQR,
|
||||
loadWallets
|
||||
showTicketQR
|
||||
} = useTicketPurchase()
|
||||
|
||||
async function handlePurchase() {
|
||||
|
|
@ -63,13 +62,6 @@ function handleClose() {
|
|||
resetPaymentState()
|
||||
}
|
||||
|
||||
// Reload wallets when dialog opens
|
||||
watch(() => props.isOpen, async (newVal) => {
|
||||
if (newVal && isAuthenticated.value) {
|
||||
await loadWallets()
|
||||
}
|
||||
})
|
||||
|
||||
// Cleanup on unmount
|
||||
onUnmounted(() => {
|
||||
cleanup()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
import { ref, computed } from 'vue'
|
||||
import { useModuleReady } from '@/composables/useModuleReady'
|
||||
import { useEvents } from '../composables/useEvents'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useAuth } from '@/composables/useAuthService'
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch } from 'vue'
|
||||
import { useUserTickets } from '../composables/useUserTickets'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useAuth } from '@/composables/useAuthService'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue