DEV Community

Discussion on: Build user authentication in Golang with JWT and mongoDB

Collapse
 
joojodontoh profile image
JOOJO DONTOH

Hi shreyngd, thank you so much for the kind words and I'm super glad this could be of help to you. You are right about the foundUser not returning the updated token which is wrong. Thanks for spotting that. I will do my best to update the article where needed.

Collapse
 
shreyngd profile image
shreyngd

In my implementation I had used FindOneAndUpdate method github.com/shreyngd/booker/blob/26....

This method returns the updated user. I don't know whether it is correct way.

Thread Thread
 
joojodontoh profile image
JOOJO DONTOH

Yes it looks good. If you dont mind some unsolicited advice 😅, you may want to consider the renaming of the function to reflect it's concern of updating tokens only. Using the FindOneAndUpdate method is good but since the fucntion is supposed to only make an update you may resort to another function returning the user object or naming the function accordingly. This is mostly for readability and clean code purposes