title: How to athorization in passport nodejs
body: <p>What i wonder is how to athorization by passport in nodejs</p>
  <p>i've tried to use this req.isAuthenticated(), but it alway works <code>false</code> even if browser has cookie session, and logined</p>
  <pre><code>req.isAuthenticated()
  </code></pre>
  <p>I config passport.ts like this</p>
  <pre><code>import { Request } from 'express';
  const passport = require('passport');
  const LocalStrategy = require('passport-local').Strategy;
  
  module.exports = (userRepository: any) =&gt; {
  
      passport.serializeUser((user: any, done: any) =&gt; {
          console.log(&quot;serializeUser good&quot;);
          done(null, user);
      });
      passport.deserializeUser((user: any, done: any) =&gt; {
          console.log(&quot;deserializeUser good&quot;);
          console.log(&quot;deserializeUser user : &quot;, user);
          done(null, user);
      });
      passport.use(new LocalStrategy({
          usernameField: 'id',
          passwordField: 'pw',
          session: true,
          passReqToCallback: false,
      }, async (id: any, pw: any, done: any) =&gt; {
  
          const result = await userRepository.findOne({
              where: {
                  userId: id
              }
          });
  
          if (!result) {
              return done(null, false, { message: 'it dont exist pw or id' });
          }
          return done(null, { userId: result.userId });
      }))
  }
  </code></pre>
  <p>and then, i've used passport.ts like this</p>
  <pre><code>const passportConfig = require('./passport');
  passportConfig(userRepository); // userRepository is entity typeorm 
  
      app.post('/login', passport.authenticate('local', {
          failureRedirect: 'http://localhost:3001/Login'
      }), (req, res) =&gt; {
          res.redirect('http://localhost:3001/');
      })
  </code></pre>
  <p>as i said, the problem is req.isAuthenticated(), but it alway works false</p>
  <p>how can i use to athorization by passport libary?</p>