- 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>
70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
const { Client } = require('pg');
|
|
require('dotenv').config();
|
|
|
|
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
|
|
}
|
|
});
|
|
|
|
async function run() {
|
|
try {
|
|
await client.connect();
|
|
console.log('Connected to database');
|
|
|
|
// Check tables
|
|
const res = await client.query(`
|
|
SELECT table_schema, table_name
|
|
FROM information_schema.tables
|
|
WHERE table_schema IN ('public', 'auth')
|
|
AND table_name IN ('users', 'otp_codes');
|
|
`);
|
|
console.log('Tables found:', res.rows);
|
|
|
|
// Inspect otp_codes schema to know columns
|
|
const otpSchema = await client.query(`
|
|
SELECT column_name, data_type
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'otp_codes';
|
|
`);
|
|
console.log('otp_codes columns:', otpSchema.rows);
|
|
|
|
// Inspect auth.users schema
|
|
// If auth.users exists, we use it. If public.users exists, check columns.
|
|
// Based on create-tables.sql: REFERENCES auth.users(id)
|
|
|
|
// Let's assume we need to insert into auth.users (if it's Supabase)
|
|
// OR maybe public.users if custom auth mimicking Supabase.
|
|
// Let's check public.users columns too.
|
|
const usersSchema = await client.query(`
|
|
SELECT column_name, data_type
|
|
FROM information_schema.columns
|
|
WHERE table_schema = 'public' AND table_name = 'users';
|
|
`);
|
|
console.log('public.users columns:', usersSchema.rows);
|
|
|
|
// Create Test User
|
|
const TEST_PHONE = '+15555555555';
|
|
const TEST_OTP = '123456';
|
|
|
|
// Logic will depend on schemas found, but let's try to be smart.
|
|
// If public.users has 'phone', we insert there?
|
|
// If auth.users exists, we probably need a UUID.
|
|
|
|
// Placeholder for insertion logic - I will run this to see schemas first
|
|
// then update the script to insert.
|
|
|
|
} catch (err) {
|
|
console.error('Database error:', err);
|
|
} finally {
|
|
await client.end();
|
|
}
|
|
}
|
|
|
|
run();
|