Skip to content

Conversation

@violacathrine
Copy link

import jwt from "jsonwebtoken";
import { User } from "../models/User.js";

const JWT_SECRET = process.env.JWT_SECRET || "supersecret";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded fallback secret can be removed for security reasons.

const token = jwt.sign(
{ userId: user._id, email: user.email },
JWT_SECRET,
{ expiresIn: "2h" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem to have 2 hour duration but next step would be refreshed token.

};

// PATCH /thoughts/:id/unlike
export const unlikeThought = async (req, res) => {
Copy link

@oskarnordin oskarnordin Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good safety code that thoughts cant go negative. Keeping things positive or neutral at least.

Update: While logged in I can spam my own like-button and it does to negative -1 and -2 I managed to get.

thoughtsQuery = thoughtsQuery.sort({ hearts: 1 });

const total = await Thought.countDocuments(query);
const results = await thoughtsQuery

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do coercion on both number and page instead of just number.

"const { message, minHearts, sort, page = 1, limit = 10 } = req.query;

const pageNum = Number(page);
const limitNum = Number(limit);

.skip((pageNum - 1) * limitNum)
.limit(limitNum);"

}
};

// DELETE /thoughts/:id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user can not delete thoughts if they're not logged in - potential new feature? Connecting it to the session ID or similar?

// connect to mongoDB then start server
connectToDatabase().then(() => {
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
Copy link

@oskarnordin oskarnordin Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catch error here?

Copy link

@oskarnordin oskarnordin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean and easily understandable code. Good comments and good setup. Very minor changes can be made.

Copy link

@JennieDalgren JennieDalgren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants