Complete LnbitsAPI migration to dependency injection pattern
- Convert LnbitsAPI from singleton to BaseService extension - Add LNBITS_API service token to DI container - Register LnbitsAPI service in base module with proper initialization order - Update AuthService to depend on injected LnbitsAPI instead of singleton - Fix BaseService to properly track LnbitsAPI dependency in getMissingDependencies - Update events API functions to use dependency injection - Resolve initialization timing issue preventing application startup 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
093846b351
commit
4a3d2012be
6 changed files with 69 additions and 18 deletions
|
|
@ -2,14 +2,14 @@
|
|||
import { ref, computed } from 'vue'
|
||||
import { BaseService } from '@/core/base/BaseService'
|
||||
import { eventBus } from '@/core/event-bus'
|
||||
import { lnbitsAPI, type LoginCredentials, type RegisterData, type User } from '@/lib/api/lnbits'
|
||||
import type { LoginCredentials, RegisterData, User } from '@/lib/api/lnbits'
|
||||
|
||||
export class AuthService extends BaseService {
|
||||
// Service metadata
|
||||
protected readonly metadata = {
|
||||
name: 'AuthService',
|
||||
version: '1.0.0',
|
||||
dependencies: [] // Auth service has no dependencies on other services
|
||||
dependencies: ['LnbitsAPI'] // Auth service depends on LnbitsAPI for authentication
|
||||
}
|
||||
|
||||
// Public state
|
||||
|
|
@ -47,7 +47,7 @@ export class AuthService extends BaseService {
|
|||
}
|
||||
|
||||
async checkAuth(): Promise<boolean> {
|
||||
if (!lnbitsAPI.isAuthenticated()) {
|
||||
if (!this.lnbitsAPI.isAuthenticated()) {
|
||||
this.debug('No auth token found - user needs to login')
|
||||
this.isAuthenticated.value = false
|
||||
this.user.value = null
|
||||
|
|
@ -56,7 +56,7 @@ export class AuthService extends BaseService {
|
|||
|
||||
try {
|
||||
this.isLoading.value = true
|
||||
const userData = await lnbitsAPI.getCurrentUser()
|
||||
const userData = await this.lnbitsAPI.getCurrentUser()
|
||||
|
||||
this.user.value = userData
|
||||
this.isAuthenticated.value = true
|
||||
|
|
@ -70,7 +70,7 @@ export class AuthService extends BaseService {
|
|||
this.isAuthenticated.value = false
|
||||
this.user.value = null
|
||||
// Clear invalid token
|
||||
lnbitsAPI.logout()
|
||||
this.lnbitsAPI.logout()
|
||||
return false
|
||||
} finally {
|
||||
this.isLoading.value = false
|
||||
|
|
@ -81,8 +81,8 @@ export class AuthService extends BaseService {
|
|||
this.isLoading.value = true
|
||||
|
||||
try {
|
||||
await lnbitsAPI.login(credentials)
|
||||
const userData = await lnbitsAPI.getCurrentUser()
|
||||
await this.lnbitsAPI.login(credentials)
|
||||
const userData = await this.lnbitsAPI.getCurrentUser()
|
||||
|
||||
this.user.value = userData
|
||||
this.isAuthenticated.value = true
|
||||
|
|
@ -102,8 +102,8 @@ export class AuthService extends BaseService {
|
|||
this.isLoading.value = true
|
||||
|
||||
try {
|
||||
await lnbitsAPI.register(data)
|
||||
const userData = await lnbitsAPI.getCurrentUser()
|
||||
await this.lnbitsAPI.register(data)
|
||||
const userData = await this.lnbitsAPI.getCurrentUser()
|
||||
|
||||
this.user.value = userData
|
||||
this.isAuthenticated.value = true
|
||||
|
|
@ -120,7 +120,7 @@ export class AuthService extends BaseService {
|
|||
}
|
||||
|
||||
async logout(): Promise<void> {
|
||||
lnbitsAPI.logout()
|
||||
this.lnbitsAPI.logout()
|
||||
this.user.value = null
|
||||
this.isAuthenticated.value = false
|
||||
this.error.value = null
|
||||
|
|
@ -134,14 +134,14 @@ export class AuthService extends BaseService {
|
|||
}
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
// Alias for checkAuth for compatibility
|
||||
await this.checkAuth()
|
||||
// Call BaseService initialize first to inject dependencies
|
||||
await super.initialize()
|
||||
}
|
||||
|
||||
async updatePassword(currentPassword: string, newPassword: string): Promise<void> {
|
||||
try {
|
||||
this.isLoading.value = true
|
||||
const updatedUser = await lnbitsAPI.updatePassword(currentPassword, newPassword)
|
||||
const updatedUser = await this.lnbitsAPI.updatePassword(currentPassword, newPassword)
|
||||
this.user.value = updatedUser
|
||||
} catch (error) {
|
||||
const err = this.handleError(error, 'updatePassword')
|
||||
|
|
@ -154,7 +154,7 @@ export class AuthService extends BaseService {
|
|||
async updateProfile(data: Partial<User>): Promise<void> {
|
||||
try {
|
||||
this.isLoading.value = true
|
||||
const updatedUser = await lnbitsAPI.updateProfile(data)
|
||||
const updatedUser = await this.lnbitsAPI.updateProfile(data)
|
||||
this.user.value = updatedUser
|
||||
} catch (error) {
|
||||
const err = this.handleError(error, 'updateProfile')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue