Skip to content

How to get user information in middleware plugin? #4747

Answered by sivanzheng
sivanzheng asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you very much. After I checked the source code of Verdaccio, I also tried to use the apiJWTmiddleware method. After your reminder, I succeeded. This is a useful method.

router.put('/:package', (req, res, next) => {
    if (auth.apiJWTmiddleware) {
        auth.apiJWTmiddleware()(req, res, () => {
            const remote_user = (req as any).remote_user as RemoteUser;
            console.log('remote', remote_user)
            logRequest(req);
            next();
        });
    } else {
        logRequest(req);
        next();
    }
});

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@juanpicado
Comment options

@sivanzheng
Comment options

Answer selected by sivanzheng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants