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