From 94c85e3a0ec7c77025918f4ad4e956ad6be194f5 Mon Sep 17 00:00:00 2001 From: padreug Date: Sun, 10 Aug 2025 12:54:00 +0200 Subject: [PATCH] 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. --- src/lib/api/lnbits.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lib/api/lnbits.ts b/src/lib/api/lnbits.ts index 5ecbba7..4e1f574 100644 --- a/src/lib/api/lnbits.ts +++ b/src/lib/api/lnbits.ts @@ -137,7 +137,24 @@ class LnbitsAPI { } async getCurrentUser(): Promise { - return this.request('/auth') + // First get basic user info from /auth + const basicUser = await this.request('/auth') + + // Then get Nostr keys from /auth/nostr/me (this was working in main branch) + try { + const nostrUser = await this.request('/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 {