webapp/src/modules/base/index.ts
padreug 034f3ce80f Implement auth guard and app branding improvements
Auth & Routing:
- Initialize auth before router guards to prevent race conditions
- Default all routes to require auth unless explicitly set to false
- Add initial route check to redirect unauthenticated users to /login
- Remove duplicate auth initialization from base module

App Branding:
- Add VITE_APP_NAME environment variable for configurable branding
- Replace hardcoded "Ariège" references with environment variable
- Update index.html, market composable to use dynamic app name

Mobile UX:
- Fix mobile dropdown auto-close on navigation item selection

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-06 19:29:48 +02:00

105 lines
No EOL
3 KiB
TypeScript

import type { App } from 'vue'
import type { ModulePlugin } from '@/core/types'
import { container, SERVICE_TOKENS } from '@/core/di-container'
import { relayHub } from './nostr/relay-hub'
// Import auth services
import { auth } from './auth/auth-service'
// Import PWA services
import { pwaService } from './pwa/pwa-service'
// Import core services
import { paymentService } from '@/core/services/PaymentService'
import { visibilityService } from '@/core/services/VisibilityService'
import { storageService } from '@/core/services/StorageService'
import { toastService } from '@/core/services/ToastService'
/**
* Base Module Plugin
* Provides core infrastructure: Nostr, Auth, PWA, and UI components
*/
export const baseModule: ModulePlugin = {
name: 'base',
version: '1.0.0',
async install(_app: App, options?: any) {
console.log('🔧 Installing base module...')
// Register core Nostr services
container.provide(SERVICE_TOKENS.RELAY_HUB, relayHub)
// Register auth service
container.provide(SERVICE_TOKENS.AUTH_SERVICE, auth)
// Register payment service
container.provide(SERVICE_TOKENS.PAYMENT_SERVICE, paymentService)
// Register visibility service
container.provide(SERVICE_TOKENS.VISIBILITY_SERVICE, visibilityService)
// Register storage service
container.provide(SERVICE_TOKENS.STORAGE_SERVICE, storageService)
// Register toast service
container.provide(SERVICE_TOKENS.TOAST_SERVICE, toastService)
// Register PWA service
container.provide('pwaService', pwaService)
// Initialize core services
relayHub.setRelayUrls(options?.config?.nostr?.relays || [])
await relayHub.initialize()
// Auth initialization moved to app.ts before router guards
await paymentService.initialize({
waitForDependencies: true, // PaymentService depends on AuthService
maxRetries: 3
})
await visibilityService.initialize({
waitForDependencies: false, // VisibilityService has no dependencies
maxRetries: 1
})
await storageService.initialize({
waitForDependencies: true, // StorageService depends on AuthService
maxRetries: 3
})
await toastService.initialize({
waitForDependencies: false, // ToastService has no dependencies
maxRetries: 1
})
console.log('✅ Base module installed successfully')
},
async uninstall() {
console.log('🗑️ Uninstalling base module...')
// Cleanup services
await relayHub.dispose()
await auth.dispose()
await paymentService.dispose()
await visibilityService.dispose()
await storageService.dispose()
await toastService.dispose()
console.log('✅ Base module uninstalled')
},
services: {
relayHub,
auth,
paymentService,
visibilityService,
storageService,
toastService,
pwaService
},
// No routes - base module is pure infrastructure
routes: [],
// No UI components at module level - they'll be imported as needed
components: {}
}
export default baseModule