title: How can i switch to another user account from an admin account
body: <p>I have a user table in which i have an Admin account and some other normal users accounts.</p>
  
  <p>I want to do all activities which for a particular user.  It should act like that activity done by same user.</p>
  
  <p>Can somebody tell me how can i switch to another account from Admin account
  without login to that account.</p>
  
  <p>Currently i use passport authentication.(passport-local)</p>
  
  <p>Here is my  code </p>
  
  <pre><code>app.get('/secure/group/login', function(req,res,next) {
          passport.authenticate('local',function(err,user,info) {
              console.log("error is "+err);
              req.logIn('tessAccount',function(err) {
                      console.log("Weer" +err);
  
              });
              console.log("dd");
  
          })(req,res,next);
      });
  
      });
  </code></pre>
  
  <p>and passport code </p>
  
  <pre><code>var LocalStrategy = require('passport-local').Strategy;
  
  module.exports = function(passport) {
      // used to serialize the user for the session
      passport.serializeUser(function(user, done) {
          done(null, user.token);
      });
  
  
  passport.use(new BearerStrategy(
    function(token, done) {
        user.tokenExist(token, function(err, user) {
                  if (err) {
                      return done(err);
                  }
                   else {
                      return done(null, user, { scope: 'all' });
                  }
        });
    }
  ));
      // used to deserialize the user
      passport.deserializeUser(function(accessToken, done) {
          user.getUserByAccessToken(accessToken, function(err, dbUser) {
              if (err) {
                  done(err);
              } else {
                  done(null, dbUser[0]);
              }
          });
      });
  
      // we are using named strategies since we have one for login and one for signup
      // by default, if there was no name, it would just be called 'local'
      passport.use('local-signup', new LocalStrategy({
              // by default, local strategy uses username and password, we will override with email
              usernameField: 'email',
              passwordField: 'password',
              passReqToCallback: true // allows us to pass back the entire request to the callback
          },
          function(req, email, password, done) {
              user.emailExists(email, function(err, exists) {
                  if (err)
                      return done(err);
                  else if (exists) {
                      return done(null, false, {
                          message: req.flash('loginMessage')
                      });
                  } else {
                      req.userDetails.status = 0;
                      req.userDetails.token = md5.digest_s(req.userDetails.email + new Date());
                      req.userDetails.userImage = config.user.image;
  
                      user.register(req.userDetails, function(err, newUser) {
                          if (err)
                              return done(err);
                          else {
                              /*Get user Shared article if exist start*/
                              getSharedArticlesOfnewlyuserIfExist(email, newUser.insertId);
                              /*Get user Shared article if exist end*/
  
                              req.userDetails.id = newUser.insertId;
                              return done(err, req.userDetails);
                          }
                      });
                  }
              });
          }));
  
      passport.use('local-login', new LocalStrategy({
              // by default, local strategy uses username and password, we will override with email
              usernameField: 'email',
              passwordField: 'password',
              passReqToCallback: true // allows us to pass back the entire request to the callback
          },
          function(req, email, password, done) {
  
              // callback with email and password from our form
              // find a user whose email is the same as the forms email
              // we are checking to see if the user trying to login already exists
              user.matchPassword({
                  email: email,
                  password: password
              }, function(err, newUser) {
                  // if there are any errors, return the error before anything else
                  if (err)
                      return done(err);
  
                  // if no user is found, return the message
                  if (newUser.length &gt; 0) {
                      var user = {
                          id: newUser[0].user_id,
                          email: newUser[0].email_id,
                          token: newUser[0].user_access_token
                      };
                      return done(null, user);
                  } else {
                      return done(null, false, {
                          message: 'Incorrect username or password.'
                      }); // req.flash is the way to set flashdata using connect-flash
                  }
  
              });
  
          }));
  </code></pre>