- Remove hardcoded database credentials from all scripts - Remove hardcoded Legacy API tokens from backend scripts - Remove hardcoded MQTT credentials from mqtt-test.js - Update backend/.env.example with DB_HOST, DB_USER, DB_PASSWORD, DB_NAME - Update backend/.env.example with LEGACY_API_TOKEN and MQTT credentials - Add dotenv config to all scripts requiring credentials - Create comprehensive documentation: - scripts/README.md - Root scripts usage - backend/scripts/README.md - Backend scripts documentation - MQTT_TESTING.md - MQTT testing guide - SECURITY_CREDENTIALS_CLEANUP.md - Security changes summary All scripts now read credentials from backend/.env instead of hardcoded values. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
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 <email>');
|
|
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();
|