Skip to content

Instantly share code, notes, and snippets.

@BerkeleyTrue
Last active April 13, 2016 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BerkeleyTrue/bfaf1e8dac5e9857ed6fe254809f7c6a to your computer and use it in GitHub Desktop.
Save BerkeleyTrue/bfaf1e8dac5e9857ed6fe254809f7c6a to your computer and use it in GitHub Desktop.
Loopback's default deserialization
passport.deserializeUser(function(id, done) {
// DB query 1:
// Find the user in the database
// This is where the largest amount of data is sent
// back form the database
self.userModel.findById(id, function(err, user) {
if (err || !user) {
return done(err, user);
}
// DB query 2:
// grab the identity object
// this contains their oauth data
// we actually don't use this information
// anywhere in our codebase
user.identities(function(err, identities) {
user.profiles = identities;
// DB query 3: grab their credentials
// This is a mistery to me why this exist.
// I'm glad we can get ride of this request
user.credentials(function(err, accounts) {
user.accounts = accounts;
done(err, user);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment