Skip to content

Comments

Happy Thoughts API - Gabriella#34

Open
gabriellaberko wants to merge 39 commits intoTechnigo:masterfrom
gabriellaberko:master
Open

Happy Thoughts API - Gabriella#34
gabriellaberko wants to merge 39 commits intoTechnigo:masterfrom
gabriellaberko:master

Conversation

@gabriellaberko
Copy link

Gabriella Berkowicz added 30 commits January 19, 2026 13:20
…actor the delete route with better error handling
…n for authenticating a user that can be used in an authorized only route
…orization header + use it to add an isCreator field to each thought
…sCreator can be computed on an object that includes the uderId
Copy link

@SaraEnderborg SaraEnderborg left a comment

Choose a reason for hiding this comment

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

Snyggt jobbat Gabriella! Du har alltid så innovativa lösningar och jag lär mig alltid något nytt av din kod. Den är clean och lätt att hänga med i med bra struktur. Bara några små tankar kring Auth bla. Grymt jobbat!

},
editToken: {
type: String,
default: () => crypto.randomUUID()

Choose a reason for hiding this comment

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

Du använder crypto.randomUUID men importerar aldrig crypto i den här filen. Fungerar det ändå kanske?


// Global middleware for authentication - To attach req.user everywhere
// I.e. if there is an accessToken in request header, find the matching user of it and attach it to every request
export const optionalAuth = async (req, res, next) => {

Choose a reason for hiding this comment

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

Jag älskar hur du har gjort det här tvåstegsmönstret med auth och optionalAuth – det är väldigt kreativt, och det verkar fungera precis så som du vill att det ska.
Men om du skulle vilja använda Bearer, kanske det kan inkluderas genom att först definiera en const authHeader och en const accessToken.

});

/* --- Execute filter and sorting --- */
const thoughts = await Thought.aggregate(filterAndSort);

Choose a reason for hiding this comment

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

Var tvungen att kolla upp "aggregate" aldrig sett förut😅 tack för att jag fick lära mig nåt nytt:) verkar dock kunna bli problem vid equals eftersom aggregate inte returnerar mongoose dokument utan vanlig js-objekt och equals hör ihop med mongoose dokument om jag fattade rätt. Nåt att kolla på kanske.

type: Date,
default: Date.now
},
editToken: {

Choose a reason for hiding this comment

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

smart med både userId och editToken för persistence i samma schema:)

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.

2 participants