Skip to content

Commit

Permalink
Merge pull request #380 from Lanaanvar/Issue(#283)
Browse files Browse the repository at this point in the history
Issue#283 - User authentication (Sign up) successful
  • Loading branch information
Trisha-tech authored Oct 16, 2024
2 parents 2cc2356 + ba09816 commit d8cd795
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules/
.env
node_modules/
17 changes: 13 additions & 4 deletions controllers/customerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit d8cd795

Please sign in to comment.