Skip to content

Can't pass req session vars to callback #48

@0xKawaka

Description

@0xKawaka

Hi,
I'm trying to pass redirectUrl to the req.session but it's undefined in the callback. Is this expected behavior?

app.get('/auth/twitter', (req, res, next) => {
  const redirectUrl = req.query.redirectUrl || envVars.ORIGIN;
  req.session.redirectUrl = redirectUrl;

  passport.authenticate('twitter', {
    scope: ['tweet.read', 'users.read', 'offline.access'],
  })(req, res, next);
});

app.get('/auth/twitter/callback',
  passport.authenticate('twitter', { failureRedirect: '/login-failure' }),
  (req, res) => {
    console.log('req.session.redirectUrl:', req.session.redirectUrl);
  }
);

Added passReqToCallback to the strategy options but didn't fix it.

{
      clientID: envVars.TWITTER_CLIENT_ID,
      clientSecret: envVars.TWITTER_CLIENT_SECRET,
      clientType: 'confidential',
      callbackURL: envVars.CALLBACK_URL,
      passReqToCallback: true,
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions