ClientX/_src/pocketbase.js

21 lines
665 B
JavaScript
Raw Normal View History

2025-04-25 21:27:00 -04:00
import PocketBase from 'pocketbase';
// Initialize Pocketbase
export const initializePocketbase = async (clientConfig, logger) => {
2025-05-08 01:52:12 +00:00
try {
const pb = new PocketBase(clientConfig.pocketbase.url);
2025-04-25 21:27:00 -04:00
2025-05-08 01:52:12 +00:00
// Authenticate with admin credentials
await pb.collection('_users').authWithPassword(
clientConfig.pocketbase.username,
clientConfig.pocketbase.password
);
2025-04-25 21:27:00 -04:00
2025-05-08 01:52:12 +00:00
logger.info('PocketBase initialized and authenticated');
return pb;
} catch (error) {
logger.error(`PocketBase initialization failed: ${error.message}`);
return new PocketBase(clientConfig.pocketbase.url);
}
2025-04-25 21:27:00 -04:00
};