Skip to content

[Bug]: setCurrentAdmin does not update theme value in session after API response #1775

Open

Description

@salaarkhan-dev

📞 Contact Details

No response


🐞 What happened?

I’m encountering an issue with the setCurrentAdmin function in AdminJS, specifically when updating the user theme (dark/light mode) via an API call. While the theme update is persisted correctly in the database, the UI does not reflect the change — because the Redux session state is not updated.


💻 Code Snippet

const [currentAdmin, setCurrentAdmin] = useCurrentAdmin();

const toggleTheme = useCallback(
  async (theme: string) => {
    console.log('before toggle theme: ', session.theme);
    console.log('changing to theme: ', theme);
    
    const response = await api.getDashboard<APIResponse>({
      params: { theme },
    });

    console.log('response theme: ', response.data.currentAdmin.theme);
    setCurrentAdmin(response.data.currentAdmin);

    console.log('Updated to theme: ', session.theme); // This still logs the old theme
  },
  [setCurrentAdmin, session]
);

🪵 Console Output

before toggle theme:  dark
changing to theme:  light
response theme:  light
Updated to theme:  dark  // Not updated!

✅ Verified

  • ✅ The updated theme is saved correctly in the database.
  • ✅ response.data.currentAdmin.theme contains the correct value (light).
  • ❌ session.theme does not update after setCurrentAdmin(response.data.currentAdmin).

🤔 Expected Behavior

After calling setCurrentAdmin, the Redux session should reflect the new admin object — including the updated theme — so that the UI can react accordingly.


🛠️ Workaround

A forced page reload updates the UI:

setCurrentAdmin(response.data.currentAdmin);
window.location.reload();

But this is not ideal for user experience and seems unnecessary.


🧪 Bug Prevalence

All the time


📦 AdminJS Dependencies Version

"@adminjs/design-system": "^4.1.1",
"@adminjs/express": "^6.1.0",
"@adminjs/passwords": "^4.0.0",
"@adminjs/prisma": "^5.0.1",
"@adminjs/themes": "^1.0.1",
"@prisma/internals": "^6.12.0",
"adminjs": "^7.7.2"

🌐 Browser

  • Chrome

📋 Relevant Log Output

before toggle theme:  dark
changing to theme:  light
response theme:  light
Updated to theme:  dark  // Not updated!

🧩 Relevant Code Causing the Issue

const [currentAdmin, setCurrentAdmin] = useCurrentAdmin();

const icon = session.theme === 'dark' ? 'Sun' : 'Moon';

const toggleTheme = useCallback(
  async (theme: string) => {
    console.log('before toggle theme: ', session.theme);
    console.log('changing to theme: ', theme);
    
    const response = await api.getDashboard<APIResponse>({
      params: { theme },
    });

    console.log('response theme: ', response.data.currentAdmin.theme);
    setCurrentAdmin(response.data.currentAdmin);

    // Reload page to refresh session state (temporary workaround)
    // window.location.reload();

    console.log('Updated to theme: ', session.theme);
  },
  [setCurrentAdmin, session]
);

Activity

  1. added
    bug
    on Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions