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,25 +4,30 @@ import { config } from '../config.js';
let token: string | null = null;
async function authenticate(): Promise<string> {
const res = await fetch(
`${config.upsnap.url}/api/collections/users/auth-with-password`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
identity: config.upsnap.username,
password: config.upsnap.password,
}),
}
);
// PocketBase v0.23+ moved admins to _superusers collection
const collections = ['_superusers', 'users'];
if (!res.ok) {
throw new Error(`UpSnap auth failed: ${res.status} ${await res.text()}`);
for (const collection of collections) {
const res = await fetch(
`${config.upsnap.url}/api/collections/${collection}/auth-with-password`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
identity: config.upsnap.username,
password: config.upsnap.password,
}),
}
);
if (res.ok) {
const data = (await res.json()) as UpSnapAuthResponse;
token = data.token;
return token;
}
}
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> {