Add username to authenticated log messages

This commit is contained in:
Deluan 2022-12-14 09:35:30 -05:00
parent f206d81afd
commit 982b604500
2 changed files with 3 additions and 0 deletions

View file

@ -217,6 +217,7 @@ func UsernameFromConfig(r *http.Request) string {
func contextWithUser(ctx context.Context, ds model.DataStore, username string) (context.Context, error) {
user, err := ds.User(ctx).FindByUsername(username)
if err == nil {
ctx = log.NewContext(ctx, "username", username)
ctx = request.WithUsername(ctx, user.UserName)
return request.WithUser(ctx, *user), nil
}

View file

@ -98,7 +98,9 @@ func authenticate(ds model.DataStore) func(next http.Handler) http.Handler {
// }
//}()
ctx = log.NewContext(r.Context(), "username", username)
ctx = request.WithUser(ctx, *usr)
ctx = request.WithUsername(ctx, usr.UserName)
r = r.WithContext(ctx)
next.ServeHTTP(w, r)