How to get user information in middleware plugin? #4747
Answered
by
sivanzheng
sivanzheng
asked this question in
Q&A
-
I want to implement a middleware plugin that can log package changes, but I don't know how to get user information in it. |
Beta Was this translation helpful? Give feedback.
Answered by
sivanzheng
Aug 2, 2024
Replies: 1 comment 2 replies
-
I try to get user information from req.remote_user but i got undefined public register_middlewares(
app: Application,
auth: IBasicAuth<CustomConfig>,
_storage: IStorageManager<CustomConfig>
): void {
const router = Router();
// Log request details to console and file
const logRequest = (req: any) => { console.log(req.remote_user) }
router.put('/:package', (req: Request, res: Response, next: NextFunction) => {
logRequest(req);
next();
});
app.use('/', router);
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.