diff --git a/packages/proxy/src/services/upsnap.ts b/packages/proxy/src/services/upsnap.ts index 476451a..604fc9c 100644 --- a/packages/proxy/src/services/upsnap.ts +++ b/packages/proxy/src/services/upsnap.ts @@ -4,25 +4,30 @@ import { config } from '../config.js'; let token: string | null = null; async function authenticate(): Promise { - 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 {