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:
parent
e1667461be
commit
cd0016744b
3 changed files with 6 additions and 54 deletions
|
|
@ -13,23 +13,14 @@ export function useAuth() {
|
|||
*/
|
||||
async function initialize(): Promise<void> {
|
||||
try {
|
||||
console.log('Initializing authentication...')
|
||||
isLoading.value = true
|
||||
error.value = null
|
||||
|
||||
const isAuth = lnbitsAPI.isAuthenticated()
|
||||
console.log('Is authenticated:', isAuth)
|
||||
|
||||
if (isAuth) {
|
||||
console.log('Getting current user...')
|
||||
if (lnbitsAPI.isAuthenticated()) {
|
||||
const user = await lnbitsAPI.getCurrentUser()
|
||||
console.log('Current user set:', user)
|
||||
currentUser.value = user
|
||||
} else {
|
||||
console.log('Not authenticated, skipping user fetch')
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Authentication initialization error:', err)
|
||||
error.value = err instanceof Error ? err.message : 'Failed to initialize authentication'
|
||||
// Clear invalid token
|
||||
await logout()
|
||||
|
|
@ -43,19 +34,15 @@ export function useAuth() {
|
|||
*/
|
||||
async function login(credentials: LoginCredentials): Promise<void> {
|
||||
try {
|
||||
console.log('Login attempt with credentials:', { username: credentials.username })
|
||||
isLoading.value = true
|
||||
error.value = null
|
||||
|
||||
await lnbitsAPI.login(credentials)
|
||||
console.log('Login successful, getting user details...')
|
||||
|
||||
// Get user details
|
||||
const user = await lnbitsAPI.getCurrentUser()
|
||||
console.log('User details after login:', user)
|
||||
currentUser.value = user
|
||||
} catch (err) {
|
||||
console.error('Login error:', err)
|
||||
error.value = err instanceof Error ? err.message : 'Login failed'
|
||||
throw err
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -30,25 +30,10 @@ export function useTicketPurchase() {
|
|||
}
|
||||
})
|
||||
|
||||
const userWallets = computed(() => {
|
||||
const wallets = currentUser.value?.wallets || []
|
||||
console.log('User wallets computed:', {
|
||||
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
|
||||
})
|
||||
const userWallets = computed(() => currentUser.value?.wallets || [])
|
||||
const hasWalletWithBalance = computed(() =>
|
||||
userWallets.value.some((wallet: any) => wallet.balance_msat > 0)
|
||||
)
|
||||
|
||||
// Generate QR code for Lightning payment
|
||||
async function generateQRCode(bolt11: string) {
|
||||
|
|
|
|||
|
|
@ -84,27 +84,11 @@ class LnbitsAPI {
|
|||
(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, {
|
||||
...options,
|
||||
headers,
|
||||
})
|
||||
|
||||
console.log('LNBits API Response:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
ok: response.ok,
|
||||
url: response.url
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
console.error('LNBits API Error:', {
|
||||
|
|
@ -116,7 +100,6 @@ class LnbitsAPI {
|
|||
}
|
||||
|
||||
const data = await response.json()
|
||||
console.log('LNBits API Response Data:', data)
|
||||
return data
|
||||
}
|
||||
|
||||
|
|
@ -151,10 +134,7 @@ class LnbitsAPI {
|
|||
}
|
||||
|
||||
async getCurrentUser(): Promise<User> {
|
||||
console.log('getCurrentUser called, accessToken:', this.accessToken ? 'present' : 'missing')
|
||||
const user = await this.request<User>('/auth')
|
||||
console.log('getCurrentUser response:', user)
|
||||
return user
|
||||
return this.request<User>('/auth')
|
||||
}
|
||||
|
||||
async updatePassword(currentPassword: string, newPassword: string): Promise<User> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue