← Back
/** Smoke test: verify Privy server-auth creds work (App ID + App Secret). */
import fs from 'node:fs';
import { PrivyClient } from '@privy-io/server-auth';

// load ../.env.privy (gitignored)
const env = {};
for (const line of fs.readFileSync(new URL('../.env.privy', import.meta.url), 'utf8').split('\n')) {
  const t = line.trim();
  if (!t || t.startsWith('#')) continue;
  const i = t.indexOf('=');
  if (i > 0) env[t.slice(0, i).trim()] = t.slice(i + 1).trim();
}

const appId = env.PRIVY_APP_ID;
const appSecret = env.PRIVY_APP_SECRET;
console.log('appId:', appId);
console.log('appSecret:', appSecret ? appSecret.slice(0, 12) + '…' : 'MISSING');

const privy = new PrivyClient(appId, appSecret);

try {
  // authenticated read — fails with 401 if creds are wrong
  const users = await privy.getUsers();
  console.log('🎯 AUTH OK — getUsers returned', Array.isArray(users) ? users.length : typeof users, 'users');
} catch (e) {
  console.log('⚠️ AUTH FAILED:', e?.message || e);
  process.exit(1);
}