How do you use the SDK from node? #272
-
Hi! Thanks for a super cool project! I'm trying to programmatically create a "migration" or "seed" script for the collections, since I dislike having config not stored in version control. I have the following script: import PocketBase from 'pocketbase';
const pocketBaseUrl = 'http://localhost:8090';
console.log(`will seed database at ${pocketBaseUrl}`);
const client = new PocketBase(pocketBaseUrl);
const user = process.env.POCKET_BASE_ADMIN_USER;
const password = process.env.POCKET_BASE_ADMIN_PASS;
if (user === undefined || password === undefined) {
throw Error('POCKET_BASE_ADMIN_USER or POCKET_BASE_ADMIN_PASS not set');
}
console.log(`${user}:${password}`);
await client.admins.authViaEmail(user, password); when I run
Environment variables are set correctly Is this expected? Am I doing something weird here? I am not very experienced with js The idea is to authenticate and then to call a bunch of Thanks in advance, let me know if I should create an issue instead. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This looks similar to #258. Try changing the SDK backend url to an ipv4, eg: const pocketBaseUrl = 'http://127.0.0.1:8090'; The reason this could resolve the issue is that go dns resolver (and most likely in other languages too) by default will first try to resolve to IPv4 then IPv6 addresses, while in Node17+ for some reason this is the opposite - IPv6 first, then IPv4. I'll try to improve the SDK error reporting in future versions. Let me know if the above doesn't work for you and I'll investigate it further. btw. The next v0.4.0 release (sometime next week) will add support for export/import of a collection schema via an API endpoint and the Admin UI. Additionally, when PocketBase is used as framework, a console command will be also available to generate a migration file with your current local collections configuration. |
Beta Was this translation helpful? Give feedback.
This looks similar to #258. Try changing the SDK backend url to an ipv4, eg:
The reason this could resolve the issue is that go dns resolver (and most likely in other languages too) by default will first try to resolve to IPv4 then IPv6 addresses, while in Node17+ for some reason this is the opposite - IPv6 first, then IPv4. I'll try to improve the SDK error reporting in future versions.
Let me know if the above doesn't work for you and I'll investigate it further.
btw. The next v0.4.0 release (sometime next week) will add support for export/import of a collection schema via an API endpoint and the Admin UI. Additionally, when PocketBase is u…