fix(proxy): support PocketBase v0.23+ _superusers auth

UpSnap uses PocketBase which moved admins to _superusers collection
in v0.23+. Try _superusers first, fallback to users.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vadim Sobinin
2026-02-10 16:12:15 +03:00
parent 420d75a3b7
commit 92bc332e7e

View File

@@ -4,8 +4,12 @@ import { config } from '../config.js';
let token: string | null = null;
async function authenticate(): Promise<string> {
// PocketBase v0.23+ moved admins to _superusers collection
const collections = ['_superusers', 'users'];
for (const collection of collections) {
const res = await fetch(
`${config.upsnap.url}/api/collections/users/auth-with-password`,
`${config.upsnap.url}/api/collections/${collection}/auth-with-password`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -16,14 +20,15 @@ async function authenticate(): Promise<string> {
}
);
if (!res.ok) {
throw new Error(`UpSnap auth failed: ${res.status} ${await res.text()}`);
}
if (res.ok) {
const data = (await res.json()) as UpSnapAuthResponse;
token = data.token;
return token;
}
}
throw new Error('UpSnap auth failed: could not authenticate as superuser or user');
}
async function getToken(): Promise<string> {
if (!token) {