I am implementing a web application in NodeJS in which a user is required to log in before visiting each page.
I implemented the user authentication with the Passport module. According to the passport guide page, I have created the serializeUser and deserializeUser user functions in passport configuration, in order to use session tracking.
In the deserializeUser function, I get the stored info from the cookie, passed in to the first parameter of the function, and search in the user table in the database to retrieve the user details and pass it to the done function.
However I see that in every request the deserialized function is called and queries the database to retrieve the user details and pass it to the done function.
My question is, whether this constant querying the database (in matters of performance and logic), to get the user object, is correct practice, or I have understood and implemented something wrong. Possibly doing something not really required?