Files
famdone/frontend/src/lib/pocketbase.ts
T
2026-09-01 11:58:43 +01:00

20 lines
763 B
TypeScript

import PocketBase from 'pocketbase';
import { SERVER_IP } from '$app/env/public';
const PB_ENDPOINT = import.meta.env.PROD ? '/pb' : `http://${SERVER_IP}:8090`;
export const pb = new PocketBase(PB_ENDPOINT);
pb.autoCancellation(false);
// Seed the browser PB singleton with the session token so shared stores can
// do authenticated reads + realtime .subscribe() from the client. When the
// session is gone (logged out), clear the authStore — the default LocalAuthStore
// persists the token in localStorage, so without this the client keeps an
// authenticated singleton and effectively stays logged in.
export function initRealtimePb(token: string) {
if (token) {
pb.authStore.save(token, null);
return true;
}
pb.authStore.clear();
return false;
}