Wrong username in "Slim menu" -> "Logged user"

Created on 23 June 2023, about 1 year ago
Updated 13 June 2024, 15 days ago

Problem/Motivation

When in production, an incorrect name is displayed in the user menu.

Steps to reproduce

This behavior is caused by caching and using \Drupal::currentUser(); which returns cached data.

Specifically this part of the code generates the problem:

    if (theme_get_setting('slim_header_action_username')) {
      $current_user = \Drupal::currentUser();
      $uid = $current_user->id();
      $account = User::load($uid);
      $variables['slim_header_action_username'] = $account->getDisplayName();
    }

Steps to reproduce the issue:

  1. drupal must be configured as in the production environment (it does not occur in the development environment)
  2. enable "Silm header -> Login button and user menu -> Show username"
  3. log in as a non-administrator user (Bob); then log out, then log in with another non-admin user (Alice);
  4. the second user (Alice) will see Bob written in the user menu the label

Proposed resolution

Before the bug fixes were released, disabling the "Show Username" option temporarily resolved the issue.

Remaining tasks

---

User interface changes

No

API changes

No

Data model changes

No

🐛 Bug report
Status

Fixed

Version

2.7

Component

Code

Created by

🇮🇹Italy arturopanetta Grotteria (RC)

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024