feat: Enhance user authentication in LNBits API
- Update getCurrentUser method to fetch Nostr keys alongside basic user info, improving user data retrieval. - Implement error handling to ensure basic user info is returned if Nostr key fetching fails, enhancing robustness of the authentication process.
This commit is contained in:
parent
390f77539e
commit
94c85e3a0e
1 changed files with 18 additions and 1 deletions
|
|
@ -137,7 +137,24 @@ class LnbitsAPI {
|
|||
}
|
||||
|
||||
async getCurrentUser(): Promise<User> {
|
||||
return this.request<User>('/auth')
|
||||
// First get basic user info from /auth
|
||||
const basicUser = await this.request<User>('/auth')
|
||||
|
||||
// Then get Nostr keys from /auth/nostr/me (this was working in main branch)
|
||||
try {
|
||||
const nostrUser = await this.request<User>('/auth/nostr/me')
|
||||
|
||||
// Merge the data - basic user info + Nostr keys
|
||||
return {
|
||||
...basicUser,
|
||||
pubkey: nostrUser.pubkey,
|
||||
prvkey: nostrUser.prvkey
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to fetch Nostr keys, returning basic user info:', error)
|
||||
// Return basic user info without Nostr keys if the endpoint fails
|
||||
return basicUser
|
||||
}
|
||||
}
|
||||
|
||||
async updatePassword(currentPassword: string, newPassword: string): Promise<User> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue