diff --git a/.gitignore b/.gitignore index 3ec544c7..40b878db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -node_modules/ -.env \ No newline at end of file +node_modules/ \ No newline at end of file diff --git a/controllers/customerController.js b/controllers/customerController.js index cde40bdc..43046da6 100644 --- a/controllers/customerController.js +++ b/controllers/customerController.js @@ -16,7 +16,7 @@ exports.registerCustomer = catchAsyncErrors(async (req, res, next) => { // Validate email format if (!validator.isEmail(email)) { return res - .status(404) + .status(400) // Changed to 400 for bad request .send( errorHandler( 404, @@ -50,7 +50,7 @@ exports.registerCustomer = catchAsyncErrors(async (req, res, next) => { }, }); - sendToken(customer, 201, res); + // sendToken(customer, 201, res); const refreshToken = jwt.sign( { id: customer._id }, process.env.REFRESH_TOKEN_SECRET @@ -78,7 +78,7 @@ exports.registerCustomer = catchAsyncErrors(async (req, res, next) => { }; const token = jwt.sign(payload, jwtSecret); - sendToken(customer, 201, res); + // sendToken(customer, 201, res); const options = { expires: new Date( @@ -88,10 +88,19 @@ exports.registerCustomer = catchAsyncErrors(async (req, res, next) => { httpOnly: true, }; + // Send response with customer and tokens res.status(201).cookie("refreshToken", refreshToken, options).json({ success: true, refreshToken, - customer, + customer :{ + name: customer.name, + email: customer.email, + avatar: customer.avatar, + role: customer.role, + _id: customer._id, + createdAt: customer.createdAt, + }, + token, }); } catch (error) { console.error("Error occurred during user registration:", error); diff --git a/index.js b/index.js index 9355b814..a616c42e 100644 --- a/index.js +++ b/index.js @@ -11,11 +11,11 @@ const errorMiddleware = require("./middlewares/error.js"); // Load environment variables from .env file dotenv.config({ path: ".env" }); -const PORT = process.env.PORT || 8080; -console.log(process.env.MONGO_URL); +const PORT = process.env.sample.PORT || 8080; +console.log(process.env.sample.MONGO_URL); /* MONGODB CONNECTION START */ -const MONGO_URL = process.env.MONGO_URL; +const MONGO_URL = process.env.sample.MONGO_URL; // CORS const cors = require("cors");