forked from grebsu/Ouroboros
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-env.js
More file actions
executable file
·46 lines (35 loc) · 1.32 KB
/
setup-env.js
File metadata and controls
executable file
·46 lines (35 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
// --- 1. Setup do Diretório de Dados ---
const dataDir = path.join(__dirname, 'data');
const usersFile = path.join(dataDir, 'users.json');
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir);
console.log('Diretório "data" criado.');
}
if (!fs.existsSync(usersFile)) {
fs.writeFileSync(usersFile, '[]', 'utf8');
console.log('Arquivo "users.json" criado.');
}
// --- 2. Setup das Variáveis de Ambiente ---
const envFilePath = path.join(__dirname, '.env.local');
// Gera a chave secreta
const secret = crypto.randomBytes(32).toString('hex');
let envFileContent = '';
// Verifica se o .env.local existe
if (fs.existsSync(envFilePath)) {
envFileContent = fs.readFileSync(envFilePath, 'utf8');
}
// Remove linhas antigas para evitar duplicatas
const lines = envFileContent.split('\n');
const newLines = lines.filter(line =>
!line.startsWith('NEXTAUTH_SECRET=') &&
!line.startsWith('NEXTAUTH_URL=')
);
// Adiciona as variáveis atualizadas
newLines.push(`NEXTAUTH_SECRET=${secret}`);
newLines.push('NEXTAUTH_URL=http://localhost:3000');
fs.writeFileSync(envFilePath, newLines.join('\n').trim());
console.log('Arquivo .env.local configurado com NEXTAUTH_SECRET e NEXTAUTH_URL.');
console.log('Setup completo! O ambiente está pronto.');