Skip to content

Commit

Permalink
fix: optional chaining to prevent crashing the logger when user not i…
Browse files Browse the repository at this point in the history
…ntialized yet
  • Loading branch information
HRemonen committed Oct 13, 2023
1 parent 2e174b0 commit 9835277
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/server/middleware/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const access = morgan as unknown as AccessLogger
const accessLogger = access((tokens, req: any, res) => {
const { user } = req

console.log(user)

const method = tokens.method(req, res)
const url = tokens.url(req, res)
const status = tokens.status(req, res)
Expand All @@ -24,10 +26,10 @@ const accessLogger = access((tokens, req: any, res) => {

const additionalInfo = inProduction
? {
userId: user.id,
username: user.username,
userIamGroups: user.iamGroups,
userLanguage: user.language,
userId: user?.id,
username: user?.username,
userIamGroups: user?.iamGroups,
userLanguage: user?.language,
method,
url,
status,
Expand Down

0 comments on commit 9835277

Please sign in to comment.