Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ GOOGLE_CLIENT_ID=your_google_client_id_here
# MongoDB (used for scan history / analytics dashboard)
MONGODB_URI=mongodb+srv://<user>:<password>@<cluster>/<db>?retryWrites=true&w=majority

# Default Admin
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=admin123
# IMAP scheduled scanning (issue #186) — used to encrypt stored inbox credentials at rest.
# Generate with: python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
IMAP_ENCRYPTION_KEY=
# Where the sqlite store for IMAP connections/scan history lives (defaults to backend/imap_connections.db)
IMAP_DB_PATH=
IMAP_DB_PATH=
26 changes: 26 additions & 0 deletions backend/seeders/adminSeeder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const User = require('../models/User');

const seedAdminUser = async () => {
try{
const adminExists = await User.findOne({ role: 'admin' });
if(!adminExists){
const email = process.env.ADMIN_EMAIL || 'admin@example.com';
const password = process.env.ADMIN_PASSWORD || 'admin123';

await User.create({
email,
password,
role: 'admin',
name: 'Admin'
});

conso;e.log('Admin user created successfully');
cnsole.log(`Email: ${email}`);
console.log(`Password: ${password}`);
}
}catch(error){
console.error('Error seeding admin user:', error);
}
};

module.exports = seedAdminUser;
2 changes: 2 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const validateEnv = require('./utils/validateEnv');
validateEnv(); // Validate environment variables
dns.setServers(["8.8.8.8", "1.1.1.1"]); // ensure SRV records resolve on all networks
const express = require("express");
const seedAdminUser = require("./seeders/adminSeeder");
const { getHealthStatus } = require('./utils/healthCheck');
const cors = require("cors");
const axios = require("axios");
Expand All @@ -22,6 +23,7 @@ const app = express();
mongoose
.connect(process.env.MONGODB_URI)
.then(() => console.log("✅ MongoDB connected"))
seedAdminUser()
.catch((err) => console.error("❌ MongoDB connection error:", err));

app.use(cors());
Expand Down
Loading