diff --git a/config/db.js b/config/db.js index 64b2a11..d0a1f59 100644 --- a/config/db.js +++ b/config/db.js @@ -2,7 +2,7 @@ const mongoose = require("mongoose"); const connectDB = async () => { try { - await mongoose.connect(process.env.MONGODB_URI, { dbName: "VG Products" }); + await mongoose.connect(process.env.MONGODB_URI, { dbName: "VG_Products" }); console.log("✅ MongoDB connected"); } catch (err) { console.error("❌ MongoDB connection error:", err); diff --git a/create_admin.js b/create_admin.js new file mode 100644 index 0000000..1257b3b --- /dev/null +++ b/create_admin.js @@ -0,0 +1,32 @@ +const mongoose = require("mongoose"); +const bcrypt = require("bcrypt"); +const User = require("./src/models/user.model.js"); +require("dotenv").config(); + +async function createAdmin() { + await mongoose.connect(process.env.MONGODB_URI, { dbName: "VG_Products" }); + console.log("Connected to MongoDB"); + + const email = "info@vgfenceproducts.com"; + const password = "VGFenceProducts@2026"; + const name = "VG Fence Admin"; + + const existing = await User.findOne({ email }); + if (existing) { + console.log("Admin user already exists"); + process.exit(0); + } + + const passwordHash = await bcrypt.hash(password, 10); + await User.create({ + name, + email, + passwordHash, + role: "admin" + }); + + console.log("Admin user created successfully!"); + process.exit(0); +} + +createAdmin().catch(console.error); diff --git a/server.js b/server.js index ea61c52..645b75f 100644 --- a/server.js +++ b/server.js @@ -23,7 +23,7 @@ connectDB() // ------------------ CORS ------------------ app.use( cors({ - origin: ["http://localhost:3500", "https://app.VG Products.co"], + origin: ["http://localhost:3000", "http://localhost:3001", "https://app.VG Products.co"], credentials: true, }) ); diff --git a/src/controllers/userauth.controller.js b/src/controllers/userauth.controller.js index b0d3c78..9e16274 100644 --- a/src/controllers/userauth.controller.js +++ b/src/controllers/userauth.controller.js @@ -10,8 +10,8 @@ async function signup(req, res) { const { name, email, mobileNumber, password } = req.body; // Validate fields - if (!name || !email || !mobileNumber || !password) { - return res.status(400).json({ error: "All fields are required" }); + if (!name || !email || !password) { + return res.status(400).json({ error: "Name, email and password are required" }); } // Check if user exists