Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13fbbb9

Browse files
fix
1 parent f9ce12c commit 13fbbb9

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

week3/prep-exercise/server/users.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export const register = async (req, res) => {
1919
if (!userName || !password) {
2020
return res
2121
.status(401)
22-
.json({ message: 'userName and password is required' })
23-
.end();
22+
.json({ message: 'userName and password is required' });
2423
}
2524

2625
try {
@@ -45,22 +44,21 @@ export const login = async (req, res) => {
4544
if (!userName || !password) {
4645
return res
4746
.status(401)
48-
.json({ message: 'userName and password is required' })
49-
.end();
47+
.json({ message: 'userName and password is required' });
5048
}
5149

5250
const allUser = database.getAll();
5351
const user = allUser.find((user) => user.userName === userName);
5452
if (!user) {
55-
res.status(404).send('user not found');
53+
res.status(404).json('user not found');
5654
return;
5755
}
5856

5957
try {
6058
const correctPassword = await bcrypt.compare(password, user.password);
6159
if (correctPassword) {
6260
const token = jwt.sign({ id: user.id }, SECRET_KEY, { expiresIn: '30m' });
63-
res.status(200).send({ message: 'you login ', token });
61+
res.status(200).json({ message: 'you login ', token });
6462
}
6563
} catch (error) {
6664
res.status(500).json({ message: 'Something went wrong with server!' });
@@ -87,7 +85,7 @@ export const getProfile = async (req, res) => {
8785
};
8886

8987
export const logout = async (req, res) => {
90-
res.status(200).send('you are logout!');
88+
res.status(200).json('you are logout!');
9189
};
9290

9391
// You can also create helper functions in this file to help you implement logic

0 commit comments

Comments
 (0)