-
Notifications
You must be signed in to change notification settings - Fork 727
Open
Labels
bugSomething isn't workingSomething isn't working
Description
📞 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.themecontains the correct value (light). - ❌
session.themedoes not update aftersetCurrentAdmin(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]
);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working