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; }