fix auth issues
This commit is contained in:
parent
c5925bd275
commit
62c4c5f735
1 changed files with 15 additions and 4 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue