Implement modular architecture with core services and Nostr integration
- Introduce a modular application structure with a new app configuration file to manage module settings and features. - Implement a dependency injection container for service management across modules. - Create a plugin manager to handle module registration, installation, and lifecycle management. - Develop a global event bus for inter-module communication, enhancing loose coupling between components. - Add core modules including base functionalities, Nostr feed, and PWA services, with support for dynamic loading and configuration. - Establish a Nostr client hub for managing WebSocket connections and event handling. - Enhance user experience with a responsive Nostr feed component, integrating admin announcements and community posts. - Refactor existing components to align with the new modular architecture, improving maintainability and scalability.
This commit is contained in:
parent
2d8215a35e
commit
519a9003d4
16 changed files with 2520 additions and 14 deletions
80
src/modules/base/auth/auth-service.ts
Normal file
80
src/modules/base/auth/auth-service.ts
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
// Copy the existing auth logic into a service class
|
||||
import { ref } from 'vue'
|
||||
import { eventBus } from '@/core/event-bus'
|
||||
|
||||
export class AuthService {
|
||||
public isAuthenticated = ref(false)
|
||||
public user = ref<any>(null)
|
||||
public isLoading = ref(false)
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
console.log('🔑 Initializing auth service...')
|
||||
|
||||
// Check for existing auth state
|
||||
this.checkAuth()
|
||||
|
||||
if (this.isAuthenticated.value) {
|
||||
eventBus.emit('auth:login', { user: this.user.value }, 'auth-service')
|
||||
}
|
||||
}
|
||||
|
||||
checkAuth(): boolean {
|
||||
// Implement your existing auth check logic here
|
||||
// For now, we'll use a simple localStorage check
|
||||
const authData = localStorage.getItem('auth')
|
||||
if (authData) {
|
||||
try {
|
||||
const parsed = JSON.parse(authData)
|
||||
this.isAuthenticated.value = true
|
||||
this.user.value = parsed
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('Invalid auth data in localStorage:', error)
|
||||
this.logout()
|
||||
}
|
||||
}
|
||||
|
||||
this.isAuthenticated.value = false
|
||||
this.user.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
async login(credentials: any): Promise<void> {
|
||||
this.isLoading.value = true
|
||||
|
||||
try {
|
||||
// Implement your login logic here
|
||||
// For demo purposes, we'll accept any credentials
|
||||
this.user.value = credentials
|
||||
this.isAuthenticated.value = true
|
||||
|
||||
// Store auth state
|
||||
localStorage.setItem('auth', JSON.stringify(credentials))
|
||||
|
||||
eventBus.emit('auth:login', { user: credentials }, 'auth-service')
|
||||
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error)
|
||||
eventBus.emit('auth:login-failed', { error }, 'auth-service')
|
||||
throw error
|
||||
} finally {
|
||||
this.isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
this.user.value = null
|
||||
this.isAuthenticated.value = false
|
||||
localStorage.removeItem('auth')
|
||||
|
||||
eventBus.emit('auth:logout', {}, 'auth-service')
|
||||
}
|
||||
|
||||
async refresh(): Promise<void> {
|
||||
// Implement token refresh logic if needed
|
||||
console.log('Refreshing auth token...')
|
||||
}
|
||||
}
|
||||
|
||||
// Export singleton instance
|
||||
export const auth = new AuthService()
|
||||
Loading…
Add table
Add a link
Reference in a new issue