feat: Enhance authentication and user management with detailed logging
- Add console logging for authentication initialization, login attempts, and user retrieval to improve debugging and traceability. - Introduce a new getCurrentUser function in useAuth for better user data management. - Update useTicketPurchase to include detailed logging for user wallets and balance checks, enhancing visibility into wallet states. - Refactor LNBits API request and response logging for clearer error handling and debugging.
This commit is contained in:
parent
217ca70334
commit
0cc0bf3555
4 changed files with 75 additions and 44 deletions
|
|
@ -85,52 +85,39 @@ class LnbitsAPI {
|
|||
}
|
||||
|
||||
// Debug logging
|
||||
if (import.meta.env.VITE_LNBITS_DEBUG === 'true') {
|
||||
console.log('LNBits API Request:', {
|
||||
url,
|
||||
method: options.method || 'GET',
|
||||
headers: options.headers,
|
||||
body: options.body
|
||||
})
|
||||
}
|
||||
console.log('LNBits API Request:', {
|
||||
url,
|
||||
method: options.method || 'GET',
|
||||
headers: headers,
|
||||
hasAccessToken: !!this.accessToken,
|
||||
endpoint
|
||||
})
|
||||
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
headers,
|
||||
})
|
||||
|
||||
// Debug logging
|
||||
if (import.meta.env.VITE_LNBITS_DEBUG === 'true') {
|
||||
console.log('LNBits API Response:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
url: response.url
|
||||
})
|
||||
}
|
||||
console.log('LNBits API Response:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
ok: response.ok,
|
||||
url: response.url
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = `HTTP ${response.status}: ${response.statusText}`
|
||||
try {
|
||||
const errorData = await response.json()
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage
|
||||
} catch {
|
||||
// If we can't parse JSON, use the default error message
|
||||
}
|
||||
|
||||
// Debug logging for errors
|
||||
if (import.meta.env.VITE_LNBITS_DEBUG === 'true') {
|
||||
console.error('LNBits API Error:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
url: response.url,
|
||||
error: errorMessage
|
||||
})
|
||||
}
|
||||
|
||||
throw new Error(errorMessage)
|
||||
const errorText = await response.text()
|
||||
console.error('LNBits API Error:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
errorText
|
||||
})
|
||||
throw new Error(`API request failed: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
const data = await response.json()
|
||||
console.log('LNBits API Response Data:', data)
|
||||
return data
|
||||
}
|
||||
|
||||
async login(credentials: LoginCredentials): Promise<AuthResponse> {
|
||||
|
|
@ -164,7 +151,10 @@ class LnbitsAPI {
|
|||
}
|
||||
|
||||
async getCurrentUser(): Promise<User> {
|
||||
return this.request<User>('/auth')
|
||||
console.log('getCurrentUser called, accessToken:', this.accessToken ? 'present' : 'missing')
|
||||
const user = await this.request<User>('/user')
|
||||
console.log('getCurrentUser response:', user)
|
||||
return user
|
||||
}
|
||||
|
||||
async updatePassword(currentPassword: string, newPassword: string): Promise<User> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue