Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Passport custom strategy req.user is not working

I've tried sending id_token from Google OAuth to server callback to verify token to retrieved user information but after serializing function req.user isn't working on other router please help !

const passportCustom = require('passport-custom');
const CustomStrategy = passportCustom.Strategy;
app.use(express.static(path.join(__dirname, 'public')));
app.use(cookieParser());
app.use(express.json());
app.use(session({
  secret: 'secret',
  resave: true,
  saveUninitialized: true,
}));
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser(function(user, done) {
  console.log("serialize", user)
  done(null, user);
});

passport.deserializeUser(function(user, done) {
  console.log(user)
  done(null, user);
});


passport.use('custom', new CustomStrategy(
  function(req, done) {
  verify(req.body.id_token).then((e) => {
    done(null, e);
  })
}
));
app.post('/auth/google/callback', passport.authenticate('custom', { failureRedirect: "/" }), async (req, res, next) => {
  console.log("test1",req.user)
});

Result in console

serialize { id: '114173065407964650600',
  name: 'threeradon jaroonchon',
  email: 'threeradon.1999@mail.kmutt.ac.th',
  img: 'https://lh3.googleusercontent.com/a-/AOh14GjfmgstP53UARlMQFnajq2CKVoVH-Oyjp248Z4r=s96-c',
  google: true }
test1 { id: '114173065407964650600',
  name: 'threeradon jaroonchon',
  email: 'threeradon.1999@mail.kmutt.ac.th',
  img: 'https://lh3.googleusercontent.com/a-/AOh14GjfmgstP53UARlMQFnajq2CKVoVH-Oyjp248Z4r=s96-c',
  google: true }

req.user is working only on path /auth/google/callback I need help as soon as possible, Thank for you help

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!