Skip to content

Commit

Permalink
adjusting comments and correcting variable name #276
Browse files Browse the repository at this point in the history
adjusting comments and correcting variable name
  • Loading branch information
sharafdin authored Mar 10, 2024
2 parents 4da4084 + d2475a5 commit 7fb998f
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export async function registerUser(req, res) {
return res.status(400).json({ message: "User already exists" });
}
// Hash the password before saving it
const hashed = await hashPassword(password);
// Create a new user instance with the hashed password and save it to the database
user = new User({ email, password: hashed });
const hashedPassword = await hashPassword(password);
// Create a new user instance and save it to the database
user = new User({ email, password: hashedPassword });
await user.save();
// Respond with the generated token
res.status(201).json({ message: "User created successfully" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export async function registerUser(req, res) {
return res.status(400).json({ message: "User already exists" });
}
// Hash the password before saving it
const hashed = await hashPassword(password);
// Create a new user instance with the hashed password and save it to the database
user = await prisma.user.create({ data: { email, password: hashed } });
const hashedPassword = await hashPassword(password);
// Create a new user instance and save it to the database
user = await prisma.user.create({
data: { email, password: hashedPassword },
});
// Respond with the created user
res.status(201).json({ message: "User created successfully" });
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export async function registerUser(req, res) {
return res.status(400).json({ message: "User already exists" });
}

const hashed = await hashPassword(password);

// Create a new user instance and save it to the database
// Hash the password before saving it
const hashedPassword = await hashPassword(password);
// Create a new user instance with the hashed password and save it to the database
user = userRepository.create({
email,
password: hashed,
password: hashedPassword,
});
await userRepository.save(user);
console.log(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export async function registerUser(req, res) {
}

// Hash the password
const hashed = await hashPassword(password);
const hashedPassword = await hashPassword(password);

// Create a new user instance and save it to the database
user = await prisma.user.create({
data: { email, password: hashed },
data: { email, password: hashedPassword },
});
// Respond with the created user
res.status(201).json({ user });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export async function registerUser(req, res) {
return res.status(400).json({ message: "User already exists" });
}
// Hash the password before saving it
const hashed = await hashPassword(password);
const hashedPassword = await hashPassword(password);
// Create a new user builder and save it to the database
user = User.build({ email, password:hashed });
user = User.build({ email, password: hashedPassword });
await user.save();
res.status(201).json({ message: "User created successfully" });
} catch (error) {
Expand All @@ -40,7 +40,7 @@ export async function loginUser(req, res) {
if (!isMatch) {
return res.status(400).json({ message: "Invalid Credentials" });
}

// Create a JWT payload and generate a token
const payload = { userId: user._id };
const token = jwt.sign(payload, jwtSecret, {
Expand All @@ -52,4 +52,4 @@ export async function loginUser(req, res) {
// Handle any errors that occur during the registration process
res.status(500).json({ message: "Server Error" });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export async function registerUser(req, res) {
return res.status(400).json({ message: "User already exists" });
}

const hashed = await hashPassword(password);
const hashedPassword = await hashPassword(password);

// Create a new user instance and save it to the database
user = userRepository.create({
email,
password: hashed,
password: hashedPassword,
});
await userRepository.save(user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export async function registerUser(req, res) {
}

// Hash the password
const hashed = await hashPassword(password);
const hashedPassword = await hashPassword(password);

// Create a new user instance and save it to the database
user = await prisma.user.create({
data: { email, password: hashed },
data: { email, password: hashedPassword },
});
// Respond with the created user
res.status(201).json({ message: "User created successfully" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export async function registerUser(req, res) {
return res.status(400).json({ message: "User already exists" });
}
// Hash the password before saving it
const hashed = await hashPassword(password);
const hashedPassword = await hashPassword(password);
// Create a new user builder and save it to the database
user = User.build({ email, password:hashed });
user = User.build({ email, password: hashedPassword });
await user.save();
res.status(201).json({ message: "User created successfully" });
} catch (error) {
Expand All @@ -40,7 +40,7 @@ export async function loginUser(req, res) {
if (!isMatch) {
return res.status(400).json({ message: "Invalid Credentials" });
}

// Create a JWT payload and generate a token
const payload = { userId: user._id };
const token = jwt.sign(payload, jwtSecret, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ export async function registerUser(req, res) {
if (user) {
return res.status(400).json({ message: "User already exists" });
}

const hashed = await hashPassword(password);

// Hash the password before saving it
const hashedPassword = await hashPassword(password);
// Create a new user instance and save it to the database
user = userRepository.create({
email,
password: hashed,
password: hashedPassword,
});
await userRepository.save(user);

Expand Down

0 comments on commit 7fb998f

Please sign in to comment.