Skip to content

Commit 9509214

Browse files
author
arijitkar
committed
updation
1 parent 811177d commit 9509214

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

routes/auth.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ router.post(
2929

3030
const errors = validationResult(req);
3131
if (!errors.isEmpty()) {
32+
TaskSuccess = false;
3233
return res.status(400).json({ TaskSuccess, errors: errors.array() });
3334
}
3435

@@ -43,12 +44,11 @@ router.post(
4344
let user = await User.findOne({ email: req.body.email });
4445

4546
if (user) {
46-
return res
47-
.status(400)
48-
.json({
49-
TaskSuccess,
50-
error: "Sorry a user with this email already exists",
51-
});
47+
TaskSuccess = false;
48+
return res.status(400).json({
49+
TaskSuccess,
50+
error: "Sorry a user with this email already exists",
51+
});
5252
}
5353

5454
user = await User.create({
@@ -65,10 +65,10 @@ router.post(
6565
const token = jwt.sign(data, JWT_SECRET);
6666
// console.log(token);
6767
TaskSuccess = true;
68-
6968
res.json({ TaskSuccess, token });
7069
} catch (err) {
7170
console.log(err);
71+
TaskSuccess = false;
7272
res.json({ TaskSuccess, error: "Some error occured" });
7373
}
7474
// .then((user) => res.json(user))
@@ -99,6 +99,7 @@ router.post(
9999

100100
const errors = validationResult(req);
101101
if (!errors.isEmpty()) {
102+
TaskSuccess = false;
102103
return res.status(400).json({ TaskSuccess, errors: errors.array() });
103104
}
104105

@@ -108,14 +109,14 @@ router.post(
108109
let user = await User.findOne({ email: req.body.email });
109110

110111
if (!user) {
111-
TaskSuccess =false
112+
TaskSuccess = false;
112113
return res
113114
.status(400)
114115
.json({ TaskSuccess, error: "Sorry wrong credentials" });
115116
}
116117

117118
const passwordCompare = await bcrypt.compare(password, user.password);
118-
119+
TaskSuccess = false;
119120
if (!passwordCompare) {
120121
return res
121122
.status(400)
@@ -133,6 +134,7 @@ router.post(
133134
res.json({ TaskSuccess, token });
134135
} catch (err) {
135136
console.log(err);
137+
TaskSuccess = false;
136138
res.json({ TaskSuccess, error: "Some error occured" });
137139
}
138140
}
@@ -149,6 +151,7 @@ router.post("/getuser", fetchuser, async (req, res) => {
149151
} catch (error) {
150152
console.log(error);
151153
// res.status(500).send("Some error occured");
154+
TaskSuccess = false;
152155
res.status(500).json({ TaskSuccess, error: "Some error occured" });
153156
}
154157
});

0 commit comments

Comments
 (0)