Add authentication #17

Manually merged
Webmaster merged 225 commits from auth into main 2025-03-08 10:37:06 +00:00
Showing only changes of commit 62c4c5f735 - Show all commits

View file

@ -257,10 +257,9 @@ export class Get {
sort?: string, sort?: string,
options?: RequestOptions, options?: RequestOptions,
): Promise<T[]> { ): Promise<T[]> {
if (!this.auth.isAuthenticated()) { // Try to get records even if authentication check fails
throw new Error("User must be authenticated to retrieve records"); // This is a workaround for cases where isAuthenticated() returns false
} // but the token is still valid for API requests
try { try {
const pb = this.auth.getPocketBase(); const pb = this.auth.getPocketBase();
const requestOptions = { const requestOptions = {
@ -277,6 +276,18 @@ export class Get {
return result.map((item) => convertUTCToLocal(item)); return result.map((item) => convertUTCToLocal(item));
} catch (err) { } catch (err) {
console.error(`Failed to get all records from ${collectionName}:`, 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; throw err;
} }
} }