refactor: Simplify authentication and wallet logic by removing debug logs

- Eliminate console logging from the authentication initialization and login processes in useAuth.ts for cleaner code.
- Streamline wallet computation in useTicketPurchase.ts by removing unnecessary logging while maintaining functionality.
- Refactor LNBits API methods to reduce logging, enhancing code clarity and maintainability.
This commit is contained in:
padreug 2025-08-01 23:25:53 +02:00
parent e1667461be
commit cd0016744b
3 changed files with 6 additions and 54 deletions

View file

@ -13,23 +13,14 @@ export function useAuth() {
*/ */
async function initialize(): Promise<void> { async function initialize(): Promise<void> {
try { try {
console.log('Initializing authentication...')
isLoading.value = true isLoading.value = true
error.value = null error.value = null
const isAuth = lnbitsAPI.isAuthenticated() if (lnbitsAPI.isAuthenticated()) {
console.log('Is authenticated:', isAuth)
if (isAuth) {
console.log('Getting current user...')
const user = await lnbitsAPI.getCurrentUser() const user = await lnbitsAPI.getCurrentUser()
console.log('Current user set:', user)
currentUser.value = user currentUser.value = user
} else {
console.log('Not authenticated, skipping user fetch')
} }
} catch (err) { } catch (err) {
console.error('Authentication initialization error:', err)
error.value = err instanceof Error ? err.message : 'Failed to initialize authentication' error.value = err instanceof Error ? err.message : 'Failed to initialize authentication'
// Clear invalid token // Clear invalid token
await logout() await logout()
@ -43,19 +34,15 @@ export function useAuth() {
*/ */
async function login(credentials: LoginCredentials): Promise<void> { async function login(credentials: LoginCredentials): Promise<void> {
try { try {
console.log('Login attempt with credentials:', { username: credentials.username })
isLoading.value = true isLoading.value = true
error.value = null error.value = null
await lnbitsAPI.login(credentials) await lnbitsAPI.login(credentials)
console.log('Login successful, getting user details...')
// Get user details // Get user details
const user = await lnbitsAPI.getCurrentUser() const user = await lnbitsAPI.getCurrentUser()
console.log('User details after login:', user)
currentUser.value = user currentUser.value = user
} catch (err) { } catch (err) {
console.error('Login error:', err)
error.value = err instanceof Error ? err.message : 'Login failed' error.value = err instanceof Error ? err.message : 'Login failed'
throw err throw err
} finally { } finally {

View file

@ -30,25 +30,10 @@ export function useTicketPurchase() {
} }
}) })
const userWallets = computed(() => { const userWallets = computed(() => currentUser.value?.wallets || [])
const wallets = currentUser.value?.wallets || [] const hasWalletWithBalance = computed(() =>
console.log('User wallets computed:', { userWallets.value.some((wallet: any) => wallet.balance_msat > 0)
currentUser: currentUser.value, )
wallets: wallets,
walletCount: wallets.length,
hasWallets: wallets.length > 0
})
return wallets
})
const hasWalletWithBalance = computed(() => {
const hasBalance = userWallets.value.some((wallet: any) => wallet.balance_msat > 0)
console.log('Wallet balance check:', {
wallets: userWallets.value,
hasBalance: hasBalance,
walletBalances: userWallets.value.map((w: any) => ({ id: w.id, balance: w.balance_msat }))
})
return hasBalance
})
// Generate QR code for Lightning payment // Generate QR code for Lightning payment
async function generateQRCode(bolt11: string) { async function generateQRCode(bolt11: string) {

View file

@ -84,27 +84,11 @@ class LnbitsAPI {
(headers as Record<string, string>)['Authorization'] = `Bearer ${this.accessToken}` (headers as Record<string, string>)['Authorization'] = `Bearer ${this.accessToken}`
} }
// Debug logging
console.log('LNBits API Request:', {
url,
method: options.method || 'GET',
headers: headers,
hasAccessToken: !!this.accessToken,
endpoint
})
const response = await fetch(url, { const response = await fetch(url, {
...options, ...options,
headers, headers,
}) })
console.log('LNBits API Response:', {
status: response.status,
statusText: response.statusText,
ok: response.ok,
url: response.url
})
if (!response.ok) { if (!response.ok) {
const errorText = await response.text() const errorText = await response.text()
console.error('LNBits API Error:', { console.error('LNBits API Error:', {
@ -116,7 +100,6 @@ class LnbitsAPI {
} }
const data = await response.json() const data = await response.json()
console.log('LNBits API Response Data:', data)
return data return data
} }
@ -151,10 +134,7 @@ class LnbitsAPI {
} }
async getCurrentUser(): Promise<User> { async getCurrentUser(): Promise<User> {
console.log('getCurrentUser called, accessToken:', this.accessToken ? 'present' : 'missing') return this.request<User>('/auth')
const user = await this.request<User>('/auth')
console.log('getCurrentUser response:', user)
return user
} }
async updatePassword(currentPassword: string, newPassword: string): Promise<User> { async updatePassword(currentPassword: string, newPassword: string): Promise<User> {