Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context is lost when using passport.js with session: false #53

Open
RobinsonZ opened this issue Jun 11, 2021 · 1 comment
Open

Context is lost when using passport.js with session: false #53

RobinsonZ opened this issue Jun 11, 2021 · 1 comment
Labels
bug Something isn't working question Further information is requested

Comments

@RobinsonZ
Copy link

When passport.js is used with session:false the async context is lost and rTracer.id() stops returning an ID. I'm pretty sure this a similar issue as described in the README and #20. That said, it seems to be something slightly different, given that #20 is an issue with express-session and I've explicitly disabled sessions here.

Specifically I'm using passport.js configured to accept JWTs with passport-jwt, using code that looks something like this:

const express = require('express');
const jwt = require('express-jwt');
const passport = require('passport');
const passportJwt = require('passport-jwt');
const rTracer = require('cls-rtracer')

passport.use('jwt', new passportJwt.Strategy(/* jwt options */));

const app = express();

app.use(passport.initialize());

app.use(rTracer.expressMiddleware());

app.use((req, res, next) => {
	console.log(rTracer.id()); // prints an id
});

app.get('/foo',
	passport.authenticate('jwt', {session: false}),
	(req, res) => {
		console.log(rTracer.id()); // prints 'undefined' 
	}
);

app.get('/bar', (req, res) => {
	console.log(rTracer.id()); // prints an id 
});

I assume this is fundamentally an issue with either passport or passport-jwt, and so it's not fixable on your end. Your readme said to submit an issue, though, so I hope this is helpful.

@puzpuzpuz puzpuzpuz added bug Something isn't working question Further information is requested labels Jun 15, 2021
@puzpuzpuz
Copy link
Owner

Indeed it looks like a potential async hooks context loss in express-jwt/passport-jwt/node-jsonwebtoken. Thanks for reporting this. If there will be more cls-rtracer users who suffer from this issue, I'll try to investigate the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants