Testing and debugging
This commit is contained in:
@@ -71,12 +71,12 @@ export const login = async (req, res) => {
|
||||
const validPassword = await bcrypt.compare(password, user.password);
|
||||
if (!validPassword) return res.status(400).json({ msg: "Wrong password" });
|
||||
|
||||
const accessToken = jwt.sign(
|
||||
const token = jwt.sign(
|
||||
{ id: user._id, admin: user.admin },
|
||||
process.env.JWT_SECRET
|
||||
);
|
||||
delete user.password;
|
||||
res.status(200).json({ accessToken, user });
|
||||
res.status(200).json({ token, user });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
|
||||
@@ -55,6 +55,9 @@ export const getFriends = async (req, res) => {
|
||||
export const patchFriend = async (req, res) => {
|
||||
try {
|
||||
const { userId, friendId } = req.params;
|
||||
if (userId === friendId) {
|
||||
return res.status(400).json({ error: "You cannot add yourself" });
|
||||
}
|
||||
const user = await User.findById(userId);
|
||||
const friend = await User.findById(friendId);
|
||||
|
||||
@@ -63,7 +66,7 @@ export const patchFriend = async (req, res) => {
|
||||
friend.friends = friend.friends.filter((id) => id !== id);
|
||||
} else {
|
||||
user.friends.push(friendId);
|
||||
friend.friends.push(id);
|
||||
friend.friends.push(userId);
|
||||
}
|
||||
|
||||
await user.save();
|
||||
|
||||
Reference in New Issue
Block a user