import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // 1. Read .env.local const envPath = path.join(__dirname, '..', '.env.local'); const envContent = fs.readFileSync(envPath, 'utf8'); const instanceMatch = envContent.match(/VITE_NCB_INSTANCE=(.+)/); if (!instanceMatch) { console.error("Could not find VITE_NCB_INSTANCE in .env.local"); process.exit(1); } const instanceId = instanceMatch[1].trim(); console.log('Using Instance:', instanceId); const BASE_URL = 'https://app.nocodebackend.com/api'; async function run() { // 2. Login console.log('Logging in...'); const loginUrl = `${BASE_URL}/user-auth/sign-in/email?Instance=${instanceId}`; console.log('Login URL:', loginUrl); // Add Origin header to mimic trusted origin const headers = { 'Content-Type': 'application/json', 'X-Database-Instance': instanceId, 'Origin': 'https://app.nocodebackend.com' }; // Login with the admin credentials from AuthPage or a test user const loginRes = await fetch(loginUrl, { method: 'POST', headers: headers, body: JSON.stringify({ email: 'streaper2@gmail.com', password: 'Kency1313' }) }); if (!loginRes.ok) { console.error('Login failed:', await loginRes.text()); return; } const cookie = loginRes.headers.get('set-cookie'); console.log('Login successful. Cookie received.'); // 3. Create Project console.log('Creating project...'); // Correct URL based on Swagger: /api/data/create/