Skip to content

Better describe difference between null/undefined #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ app.use(session({
To maintain a login session, Passport serializes and deserializes user
information to and from the session. The information that is stored is
determined by the application, which supplies a `serializeUser` and a
`deserializeUser` function.
`deserializeUser` function. Note that in the `deserializeUser` callback,
we need to make sure to never send `undefined`, as that would cause an
error to be thrown. Instead, pass `null` or `false`.


```javascript
passport.serializeUser(function(user, cb) {
Expand Down Expand Up @@ -123,7 +126,7 @@ passport.serializeUser(function(user, cb) {
passport.deserializeUser(function(id, cb) {
db.get('SELECT * FROM users WHERE id = ?', [ id ], function(err, user) {
if (err) { return cb(err); }
return cb(null, user);
return cb(null, user || null); // If `user` is undefined, we have to provide null instead
});
});
```
Expand Down