Skip to content

Commit

Permalink
new server
Browse files Browse the repository at this point in the history
  • Loading branch information
paysonism authored Apr 20, 2024
1 parent 5800ca1 commit 7f1ce58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PORT = 1337
MONGODB_URL = mongodb+srv://jayesh:jayesh@cluster0.7bqqxwy.mongodb.net/whatsappClone
MONGODB_URL = mongodb+srv://payson:ontop@1337.dhr7zez.mongodb.net/?retryWrites=true&w=majority&appName=1337
JWT_SECRET = masai
REF_SECRET = Masai
16 changes: 8 additions & 8 deletions routes/User.Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ userRoutes.post("/signup", async (req, res) => {
try {
const userPresent = await UserModel.find({ email: email });
if (userPresent.size > 0) {
return res.status(400).json({ error: "User is already present." });
return res.status(400).json({ error: "Email has already been used" });
}

const hashed_password = bcrypt.hashSync(password, 4);
Expand All @@ -26,7 +26,7 @@ userRoutes.post("/signup", async (req, res) => {
});
await user.save();

res.json({ success: "User created successfully" });
res.json({ success: "Successfully Registered" });
} catch (error) {
res.send({ error: "Something went wrong", error: error.message });
}
Expand All @@ -39,12 +39,12 @@ userRoutes.post("/login", async (req, res) => {
if (!user) {
return res
.status(400)
.json({ error: "username and password is wrong" });
.json({ error: "Incorrect Login Credentials" });
}

const isPasswordMatch = await bcrypt.compare(password, user.password);
if (!isPasswordMatch) {
return res.status(400).json({ error: "Wrong credential" });
return res.status(400).json({ error: "Incorrect Login Credentials" });
}

const token = jwt.sign({ userId: user._id }, process.env.JWT_SECRET, {
Expand All @@ -56,21 +56,21 @@ userRoutes.post("/login", async (req, res) => {
{ expiresIn: 30000 }
);
return res.status(200).json({
success: "User login successfully",
success: "Logged in!",
token: token,
reftoken: reftoken,
userId: user._id,
});
} catch (error) {
res.send({ error: "Something went wrong", error: error.message });
res.send({ error: "Something went wrong: ", error: error.message });
}
});

userRoutes.get("/logout", async (req, res) => {
const token = req.headers.authorization.split(" ")[1];
const blacklist = new BlacklistModel({ token });
await blacklist.save();
return res.status(200).json({ message: "User logged out successfully" });
return res.status(200).json({ message: "Successfully logged out" });
});
userRoutes.get("/allUser", async (req, res) => {
const { userId } = req.query;
Expand Down Expand Up @@ -145,7 +145,7 @@ userRoutes.get("/apiRefresh", async (req, res) => {

res.send({ token });
} catch (error) {
return res.status(403).json({ message: "Login First" });
return res.status(403).json({ message: "Please login before using the app" });
}
});

Expand Down

0 comments on commit 7f1ce58

Please sign in to comment.