feat: implement tenant impersonation for super admins
Some checks failed
Build and Deploy / build-and-push (push) Failing after 1m38s

- Added POST /api/impersonate/:tenantId to generate a specialized tenant-scoped JWT.

- Added UI button in SuperAdmin page to trigger impersonation.

- Saved original super_admin token to localStorage to allow returning without re-login.

- Added 'Retornar ao Painel Central' button in sidebar to quickly revert to super admin status.
This commit is contained in:
Cauê Faleiros
2026-03-10 16:20:06 -03:00
parent ee3b9f4ce6
commit b7f9efd0d1

View File

@@ -7,7 +7,7 @@ import {
import { import {
getAttendances, getUsers, getUserById, logout, searchGlobal, getAttendances, getUsers, getUserById, logout, searchGlobal,
getNotifications, markNotificationAsRead, markAllNotificationsAsRead, getNotifications, markNotificationAsRead, markAllNotificationsAsRead,
deleteNotification, clearAllNotifications deleteNotification, clearAllNotifications, returnToSuperAdmin
} from '../services/dataService'; } from '../services/dataService';
import { User } from '../types'; import { User } from '../types';
@@ -212,7 +212,19 @@ export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
</nav> </nav>
{/* User Profile Mini - Now Clickable to Profile */} {/* User Profile Mini - Now Clickable to Profile */}
<div className="p-4 border-t border-zinc-100 dark:border-dark-border"> <div className="p-4 border-t border-zinc-100 dark:border-dark-border space-y-3">
{localStorage.getItem('ctms_super_admin_token') && (
<button
onClick={() => {
if (returnToSuperAdmin()) {
window.location.href = '/';
}
}}
className="w-full flex items-center justify-center gap-2 py-2 px-3 bg-zinc-900 dark:bg-brand-yellow text-white dark:text-zinc-950 rounded-lg text-xs font-bold hover:opacity-90 transition-colors"
>
Retornar ao Painel Central
</button>
)}
<div className="flex items-center gap-3 p-2 rounded-lg bg-zinc-50 dark:bg-dark-bg/50 border border-zinc-100 dark:border-dark-border group"> <div className="flex items-center gap-3 p-2 rounded-lg bg-zinc-50 dark:bg-dark-bg/50 border border-zinc-100 dark:border-dark-border group">
<div <div
onClick={() => navigate('/profile')} onClick={() => navigate('/profile')}