Code Monkey home page Code Monkey logo

Comments (5)

vladiulianbogdan avatar vladiulianbogdan commented on May 13, 2024 4

I was unable to do it with nestjs-configure-after because in our system the authentication is not performed with a middleware, but with a decorator on top of the controller method. So, if I understand correctly, the logging middleware will catch and store the request before the decorator in the controller is called.

My solution to this problem is to use the logger.assign (https://github.com/iamolegga/nestjs-pino#assign-extra-fields-for-future-calls) method to add the user id information to the log.

from nestjs-pino.

MikeKoval avatar MikeKoval commented on May 13, 2024 2

@vladiulianbogdan can you share snippet how you resolved that issue with decorators pls?
do you use logger.assign inside decorator or at controller itself? if in decorator, how do you pass it there?

from nestjs-pino.

iamolegga avatar iamolegga commented on May 13, 2024

Hi, for such purpose I've created this library, because nest doesn't have guarantee of modules registration and middlewares order, you can see discussion for same problem of middlewares order in another my package. All you need is wrap this module in another one with extra decorator, and add one to your passport/auth/whatever module.

and the second part is you need to find specific option to add new properties to logs

Feel free to ping me with your code exmaples

from nestjs-pino.

EdByrnee avatar EdByrnee commented on May 13, 2024

Did you manage to find a solution for this?

from nestjs-pino.

vladiulianbogdan avatar vladiulianbogdan commented on May 13, 2024

I haven't tried yet what iamolegga suggested, but I will do it as soon as possible and I will let you know.

from nestjs-pino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.