From 62c4c5f735cc84dd51ce260584a717b67dfa14fc Mon Sep 17 00:00:00 2001 From: chark1es Date: Sat, 1 Mar 2025 03:09:45 -0800 Subject: [PATCH] fix auth issues --- src/scripts/pocketbase/Get.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/scripts/pocketbase/Get.ts b/src/scripts/pocketbase/Get.ts index abccd66..20ae25e 100644 --- a/src/scripts/pocketbase/Get.ts +++ b/src/scripts/pocketbase/Get.ts @@ -257,10 +257,9 @@ export class Get { sort?: string, options?: RequestOptions, ): Promise { - if (!this.auth.isAuthenticated()) { - throw new Error("User must be authenticated to retrieve records"); - } - + // Try to get records even if authentication check fails + // This is a workaround for cases where isAuthenticated() returns false + // but the token is still valid for API requests try { const pb = this.auth.getPocketBase(); const requestOptions = { @@ -277,6 +276,18 @@ export class Get { return result.map((item) => convertUTCToLocal(item)); } catch (err) { console.error(`Failed to get all records from ${collectionName}:`, err); + + // If the error is authentication-related, check if we're actually authenticated + if ( + err instanceof Error && + (err.message.includes('auth') || err.message.includes('authentication')) + ) { + if (!this.auth.isAuthenticated()) { + console.error("Authentication check failed in getAll"); + throw new Error("User must be authenticated to retrieve records"); + } + } + throw err; } }