const { Client } = require('pg'); require('dotenv').config({ path: '../backend/.env' }); const client = new Client({ user: process.env.DB_USER, host: process.env.DB_HOST, database: process.env.DB_NAME, password: process.env.DB_PASSWORD, port: parseInt(process.env.DB_PORT || '5432'), ssl: { rejectUnauthorized: false } }); const email = process.argv[2]; if (!email) { console.error('Usage: node fetch-otp.js '); process.exit(1); } async function run() { try { await client.connect(); // Get the latest OTP for the email const res = await client.query(` SELECT code FROM public.otp_codes WHERE email = $1 ORDER BY created_at DESC LIMIT 1 `, [email]); if (res.rows.length > 0) { console.log(res.rows[0].code); } else { console.error('No OTP found'); process.exit(1); } } catch (err) { console.error('Database error:', err); process.exit(1); } finally { await client.end(); } } run();