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
|
|
@ -218,7 +218,7 @@
|
|||
import { computed, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useMarketStore } from '../stores/market'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useAuth } from '@/composables/useAuthService'
|
||||
import { useMarket } from '../composables/useMarket'
|
||||
// import { useOrderEvents } from '@/composables/useOrderEvents' // TODO: Move to market module
|
||||
import { Button } from '@/components/ui/button'
|
||||
|
|
|
|||
|
|
@ -321,7 +321,7 @@ import {
|
|||
} from 'lucide-vue-next'
|
||||
import type { OrderStatus } from '@/stores/market'
|
||||
import { nostrmarketService } from '../services/nostrmarketService'
|
||||
import { auth } from '@/composables/useAuth'
|
||||
import { auth } from '@/composables/useAuthService'
|
||||
|
||||
const router = useRouter()
|
||||
const marketStore = useMarketStore()
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ import { useRouter } from 'vue-router'
|
|||
import { useMarketStore } from '../stores/market'
|
||||
// import { useOrderEvents } from '@/composables/useOrderEvents' // TODO: Move to market module
|
||||
import { injectService, SERVICE_TOKENS } from '@/core/di-container'
|
||||
import { auth } from '@/composables/useAuth'
|
||||
import { auth } from '@/composables/useAuthService'
|
||||
import { useLightningPayment } from '../composables/useLightningPayment'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@
|
|||
import { computed, ref, watch } from 'vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
import QRCode from 'qrcode'
|
||||
import { useAuth } from '@/composables/useAuthService'
|
||||
import type { NostrmarketPaymentRequest } from '../services/nostrmarketService'
|
||||
import {
|
||||
Dialog,
|
||||
|
|
@ -125,6 +126,9 @@ const emit = defineEmits<{
|
|||
'payment-completed': [orderId: string]
|
||||
}>()
|
||||
|
||||
// Auth
|
||||
const auth = useAuth()
|
||||
|
||||
// Computed
|
||||
const lightningInvoice = computed(() => {
|
||||
if (!props.paymentRequest) return null
|
||||
|
|
@ -251,10 +255,6 @@ const payWithWallet = async () => {
|
|||
// Import the payment API
|
||||
const { payInvoiceWithWallet } = await import('@/lib/api/events')
|
||||
|
||||
// Get the current user's wallet info
|
||||
const { useAuth } = await import('@/composables/useAuth')
|
||||
const auth = useAuth()
|
||||
|
||||
if (!auth.currentUser.value?.wallets?.[0]?.id || !auth.currentUser.value?.wallets?.[0]?.adminkey) {
|
||||
toast.error('Please connect your wallet to pay')
|
||||
return
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { config } from '@/lib/config'
|
|||
import { nostrmarketService } from '../services/nostrmarketService'
|
||||
import { nip04 } from 'nostr-tools'
|
||||
import { useAsyncOperation } from '@/core/composables/useAsyncOperation'
|
||||
import { auth } from '@/composables/useAuth'
|
||||
import { auth } from '@/composables/useAuthService'
|
||||
|
||||
// Nostr event kinds for market functionality
|
||||
const MARKET_EVENT_KINDS = {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ref } from 'vue'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useAuth } from '@/composables/useAuthService'
|
||||
import { useMarketStore } from '../stores/market'
|
||||
|
||||
// Simplified bolt11 parser to extract payment hash
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { finalizeEvent, type EventTemplate, nip04 } from 'nostr-tools'
|
||||
import { BaseService } from '@/core/base/BaseService'
|
||||
import type { Stall, Product, Order } from '@/stores/market'
|
||||
import { auth } from '@/composables/useAuth'
|
||||
import { auth } from '@/composables/useAuthService'
|
||||
|
||||
export interface NostrmarketStall {
|
||||
id: string
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { ref, computed, readonly, watch } from 'vue'
|
|||
import { invoiceService } from '@/core/services/invoiceService'
|
||||
import { paymentMonitor } from '../services/paymentMonitor'
|
||||
import { nostrmarketService } from '../services/nostrmarketService'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useAuth } from '@/composables/useAuthService'
|
||||
import { injectService, SERVICE_TOKENS } from '@/core/di-container'
|
||||
import type { LightningInvoice } from '@/core/services/invoiceService'
|
||||
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ import { ref, computed, onMounted } from 'vue'
|
|||
import { useRoute } from 'vue-router'
|
||||
import { useMarketStore } from '@/stores/market'
|
||||
import { injectService, SERVICE_TOKENS } from '@/core/di-container'
|
||||
import { auth } from '@/composables/useAuth'
|
||||
import { auth } from '@/composables/useAuthService'
|
||||
import {
|
||||
Card,
|
||||
CardHeader,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue