1.7 KiB
1.7 KiB
Iteration Log: Full Target User Account Impersonation in View-As Mode
-
Requested: Implement full target user account impersonation for the "View-As" feature so that admins inspect the dashboard 100% as the target user account (role, site_uuid, agent_uuids, company_name), with instant session destruction on logout or exit.
-
Workflow: Test-Driven Development (TDD) Workflow.
-
Steps Taken:
- Created TDD test
test/view_as_full_impersonation_test.jsto assert target user metadata adoption and backend middleware user lookup. - Ran
node test/view_as_full_impersonation_test.js-> Confirmed RED failure phase as expected. - Modified
backend/routes/auth/viewAs.jsto accepttarget_user_idandtarget_usernameand generate view-as tokens containing target user identity. - Modified
backend/middleware/auth.jsto look upUser.findById(viewDecoded.target_user_id)and adopt the target user's exactrole,site_uuid,agent_uuids,agent_uuid, andcompany_nameintoreq.user. - Updated
src/lib/admin-api.ts(startViewAsUser) andsrc/app/(dashboard)/user-accounts/page.tsxto passuser.idand target user details to backend. - Verified
SidebarProfile.tsx,useInactivityTimeout.ts, andlogin/page.tsxcontinue to wipelocalStorage.removeItem('backone_view_as')on sign out or login. - Ran
node test/view_as_full_impersonation_test.js-> GREEN pass achieved. - Ran
npx tsc --noEmit-> 0 TypeScript compilation errors. - Ran
npm run build-> Clean production build.
- Created TDD test
-
Outcome: View-As mode now provides 100% full impersonation of target user accounts while preserving audit trails and guaranteeing instant session cleanup on logout.