cre-sync/scripts/seed-test-user.ts
BusyBee3333 4e6467ffb0 Add CRESync CRM application with Setup page
- Build complete Next.js CRM for commercial real estate
- Add authentication with JWT sessions and role-based access
- Add GoHighLevel API integration for contacts, conversations, opportunities
- Add AI-powered Control Center with tool calling
- Add Setup page with onboarding checklist (/setup)
- Add sidebar navigation with Setup menu item
- Fix type errors in onboarding API, GHL services, and control center tools
- Add Prisma schema with SQLite for local development
- Add UI components with clay morphism design system

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 17:30:55 -05:00

78 lines
2.4 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
import Database from 'better-sqlite3';
import crypto from 'crypto';
import path from 'path';
// Create database connection
const dbPath = path.resolve(process.cwd(), 'prisma', 'dev.db');
const database = new Database(dbPath);
const adapter = new PrismaBetterSqlite3(database);
const prisma = new PrismaClient({ adapter });
// Simple encryption for the access token (matching the app's encryption)
const ALGORITHM = 'aes-256-gcm';
const IV_LENGTH = 16;
function encrypt(text: string, key: string): string {
const iv = crypto.randomBytes(IV_LENGTH);
const cipher = crypto.createCipheriv(
ALGORITHM,
Buffer.from(key, 'hex'),
iv
);
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
const authTag = cipher.getAuthTag();
return iv.toString('hex') + authTag.toString('hex') + encrypted;
}
async function main() {
// Use the ENCRYPTION_KEY from .env or a proper 32-byte (64 hex char) dev key
const encryptionKey = process.env.ENCRYPTION_KEY || '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
// GHL Credentials
const GHL_LOCATION_ID = 'n2RYjuDNBOnOrUDAaSEU';
const GHL_ACCESS_TOKEN = 'd31f6728-ee7a-4625-918e-ac569fdf4a07';
// Create or update test user
const hashedPassword = crypto.createHash('sha256').update('testpass123').digest('hex');
const user = await prisma.user.upsert({
where: { email: 'test@cresync.com' },
update: {
ghlLocationId: GHL_LOCATION_ID,
ghlAccessToken: encrypt(GHL_ACCESS_TOKEN, encryptionKey),
role: 'SUPER_ADMIN',
},
create: {
email: 'test@cresync.com',
passwordHash: hashedPassword,
firstName: 'Test',
lastName: 'User',
role: 'SUPER_ADMIN',
ghlLocationId: GHL_LOCATION_ID,
ghlAccessToken: encrypt(GHL_ACCESS_TOKEN, encryptionKey),
},
});
console.log('✅ Test user created/updated:');
console.log(` Email: test@cresync.com`);
console.log(` Password: testpass123`);
console.log(` GHL Location ID: ${GHL_LOCATION_ID}`);
console.log(` Role: SUPER_ADMIN`);
console.log('');
console.log('🚀 You can now start the dev server and log in!');
}
main()
.catch((e) => {
console.error('Error:', e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});