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

User: ':remote-user' does not show logged-in user but - #283

Closed
khteh opened this issue Sep 7, 2023 · 1 comment
Closed

User: ':remote-user' does not show logged-in user but - #283

khteh opened this issue Sep 7, 2023 · 1 comment

Comments

@khteh
Copy link

khteh commented Sep 7, 2023

I am using SPDY server for HTTP/2 for my React.JS / Next.JS application. Unfortunately this solution needs to use Express.JS and therefore this is what I do to have request logging:

    const format = json({
      IP: ':remote-addr',
      User: ':remote-user',
      Timestamp: ':date[clf]',
      Method: ':method',
      Path: ':url',
      Protocol: 'HTTP/:http-version',
      Status: ':status',
      ContentLength: ':res[content-length]',
      Referrer: ':referrer',
      Agent: ':user-agent',
      ResponseTime: ':response-time ms',
    })

The log shows that ALL users are -. How can I have the logged in user in that logging field?

@khteh khteh changed the title User: ':remote-user' does not show logged in user but - User: ':remote-user' does not show logged-in user but - Sep 7, 2023
@jonchurch
Copy link
Member

jonchurch commented Feb 7, 2025

There's not enough code here to tell. Morgan reads req.user etc to populate this field. If the requet doesn't have that set when the logs are generated, it will be empty.

You need to have auth setup in you express app and popualate that field if you want to log it.

But since you are handing the request off to Next, it can modify the req object however it wants. So no guarantee that req.user is set unless you are setting it yourself or next is.

@jonchurch jonchurch closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants