V
V
vetsmen2017-10-20 22:50:13
JavaScript
vetsmen, 2017-10-20 22:50:13

Why do we need serializeUser and deserializeUser, as well as process.nextTick?

I use passport-vkontakte for authorization in the application via VK.
Two questions:
1) Why do we need serializeUser and deserializeUser
2) Why do we need processNexttick
About the first point:

// Passport session setup.
//   To support persistent login sessions, Passport needs to be able to
//   serialize users into and deserialize users out of the session.  Typically,
//   this will be as simple as storing the user ID when serializing, and finding
//   the user by ID when deserializing.  However, since this example does not
//   have a database of user records, the complete VK profile is serialized
//   and deserialized.
passport.serializeUser(function(user, done) {
  done(null, user);
});

passport.deserializeUser(function(obj, done) {
  done(null, obj);
});

Although there are comments, I don’t really understand the essence of serelization and deserialization. During authorization, the main strategy is called, in which you can do all the necessary things (including entering the user into the database or checking something), but why these functions?
About the second point:
passport.use(new VkStrategy(
  {
    clientID: VK_APP_ID,
    clientSecret: VK_APP_SECRET,
    callbackURL: "http://localhost:3000/auth/vk/callback",
    scope: ['email'],
    profileFields: ['email'],
  },
  function verify(accessToken, refreshToken, params, profile, done) {
    // asynchronous verification, for effect...
    process.nextTick(function () {
      return done(null, profile);
    });
  }
));

"asynchronous verification, for effect..." is an incomprehensible comment, why is this nextTick here? What happens if I remove it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Umid, 2018-01-02
@DarCKoder

More than three months have already passed, but maybe it will help someone:
https://habrahabr.ru/post/201206/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question