Skip to content

Commit 08845a5

Browse files
committed
Added a check if the user exists for updating token
1 parent 3b50859 commit 08845a5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/controllers/v3/utils/user.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ const userEndpoint = async (req, res, next) => {
3131
});
3232
}
3333

34+
// Check if the user with the given _id exists
35+
const userExists = await Users.exists({ _id: id });
36+
37+
if (!userExists) {
38+
return res.status(404).json({
39+
message: 'User not found',
40+
});
41+
}
42+
3443
// Update user's token in the database
35-
await Users.updateOne(
36-
{ _id: { $eq: id } },
37-
{ $set: { token: token } },
38-
{ upsert: true }, // Create the document if it doesn't exist
39-
);
44+
await Users.updateOne({ _id: { $eq: id } }, { $set: { token: token } });
4045

4146
return res.status(200).json({
4247
message: 'Token updated successfully',

0 commit comments

Comments
 (0)