Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

passport serializeUser

passport.serializeUser(function(user, done) {
    done(null, user.id);
});              │
                 │ 
                 │
                 └─────────────────┬──→ saved to session
                                   │    req.session.passport.user = {id: '..'}
                                   │
                                   ↓           
passport.deserializeUser(function(id, done) {
                   ┌───────────────┘
                   │
                   ↓ 
    User.findById(id, function(err, user) {
        done(err, user);
    });            └──────────────→ user object attaches to the request as req.user   
});
Comment

passportjs serializeuser

passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  User.findById(id, function(err, user) {
    done(err, user);
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: looping queryselectorall 
Javascript :: string interpolation in javascript 
Javascript :: select a particular sibling jquey 
Javascript :: convert utc to pst javascript 
Javascript :: toastr.success 
Javascript :: vue js tutorial 
Javascript :: even or odd in javascript 
Javascript :: object.fromentries 
Javascript :: convert a string to number in javascript 
Javascript :: express send code 
Javascript :: javascript replace with UpperCase 
Javascript :: adding all elements of an array javascript 
Javascript :: javascript swap variables 
Javascript :: setting usestate to prop 
Javascript :: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 
Javascript :: Limit text to specified number of words using Javascript 
Javascript :: react does not send the cookie automatically 
Javascript :: js sort object properties alphabetically 
Javascript :: js array to string 
Javascript :: use effect react 
Javascript :: axios.filter 
Javascript :: firebase admin delete user 
Javascript :: filter object js 
Javascript :: clearing cookie in js 
Javascript :: api.fetch saga 
Javascript :: min heap javascript 
Javascript :: how to pass data in body of delete request angular 
Javascript :: remover ultimo character string javascript 
Javascript :: javascript array findindex 
Javascript :: image file size in react-dropzone 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =