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

UNLESS method does not work with restify v11 #306

Open
renatomotorline opened this issue Feb 6, 2023 · 4 comments
Open

UNLESS method does not work with restify v11 #306

renatomotorline opened this issue Feb 6, 2023 · 4 comments
Assignees
Labels

Comments

@renatomotorline
Copy link

renatomotorline commented Feb 6, 2023

Describe the bug
Hi, I'm trying update to restify 11.0.0. But when I put the restify-jwt-community middleware I start to get on all request this error:
Error [ERR_HTTP_HEADERS_SENT]: Cannot render headers after they are sent to the client
Even if the request is on the unless path.
If I comment server.use(rjwt({ secret: config.JWT_SECRET }).unless({path: ['/auth/token']})); the requests that don't use jwt token start to work fine.

UPDATE NOTE:
If remove the unless works fine.
As alternative to unless I did this:

server.use(rjwt({ secret: config.JWT_SECRET }), function (err, req, res, next) {
    if (err) {
        var path = [
            '/path1',
            '/path2',
        ];
        var matches = path.filter(function (pattern) {
            return new RegExp(pattern).test(req.url);
        });
        // If url match some path
        if (matches.length > 0) {
            return next();
        }
        return next(err);
    }
    
    return next();
});

To Reproduce

const rjwt = require('restify-jwt-community');
server.use(rjwt({ secret: config.JWT_SECRET }).unless({path: ['/auth/token']}));

Expected behavior
This code on restify 8.5.1 works fine.

System:

  • OS: Docker node:16-alpine
  • Restify JWT Community version 1.1.29
@frbuceta
Copy link
Owner

Can you test if it works with version 2.0.0.0 of the package?

@frbuceta frbuceta changed the title restify-jwt-community UNLESS method does not work with restify v11 Mar 27, 2023
@mohammad-mahmoodi
Copy link

No, it does not work in version 2.0.0 either.

@Joeao
Copy link

Joeao commented Oct 3, 2023

Experiencing this with 2.0.0, using restify 11.1.0.

The reason for Error [ERR_HTTP_HEADERS_SENT]: Cannot render headers after they are sent to the client being seen is that each following request is being triggered twice.

I've implemented the workaround provided in the original comment, which works just fine.

@MaikelFC
Copy link

MaikelFC commented Dec 5, 2023

Also encountered this problem using 2.0.0 and restifiy 11.1.0,
The work around in the original comment worked for me.

Took forever to find out what was causing the request to process twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants