import dotenv from "dotenv";
import PocketBase from "pocketbase";

dotenv.config();

const pb = new PocketBase(process.env.PB_URL);

const email = process.env.PB_EMAIL;
const password = process.env.PB_PASSWORD;

if (!email || !password) {
  throw new Error("Missing PB_EMAIL or PB_PASSWORD in .env");
}
try {
  await pb.collection("users").authWithPassword(email, password);
} catch (err: any) {
  console.error("Error response:", err.response);
}

const authData = await pb.collection("users").authWithPassword(email, password);

console.log("Valid:", pb.authStore.isValid);
console.log("Token:", pb.authStore.token);
console.log("User ID:", pb.authStore.record?.id);

pb.authStore.clear();