Skip to content

feat(backoffice): add user impersonation UI for admins - #108

Draft
geourjoa wants to merge 1 commit into
mainfrom
feat/impersonation-backoffice-button
Draft

feat(backoffice): add user impersonation UI for admins#108
geourjoa wants to merge 1 commit into
mainfrom
feat/impersonation-backoffice-button

Conversation

@geourjoa

@geourjoa geourjoa commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Cross-repo dependency: requires backend PR archetype-pal/backend#152 (POST /api/v1/auth/management/users/{id}/impersonate/, superuser-only, token-swap) to work end-to-end.

There was previously no frontend UI for impersonation at all. Adds:

  • An "Impersonate" action on the backoffice users table (app/backoffice/users/page.tsx), disabled with an explanatory tooltip for the current user's own row and for staff/superuser targets (mirrors the backend's own restrictions), gated behind a confirmation dialog.
  • startImpersonation/stopImpersonation/isImpersonating on the auth context (contexts/auth-context.tsx): stashes the admin's real token in a second cookie while impersonating, restores it on "stop".
  • A site-wide ImpersonationBanner (mounted in the root layout, so it's visible on both the public site and backoffice — impersonation targets are always non-staff, so the session lands on the public site after switching) with a "Stop impersonating" button.
  • services/backoffice/users.ts: impersonateUser(token, id).

Test plan

  • vitest run — full suite 117 files / 1171 tests passed (19 new)
  • tsc --noEmit clean
  • eslint / prettier --check clean
  • Smoke test against the real backend once #152 is merged

No new dependencies.


Side note (unrelated, left untouched): noticed messages/en.json's login.signIn key holds French text ("Se connecter") in the English catalogue — pre-existing, out of scope here.

Adds a superuser-only "impersonate" action to the backoffice users
table, backed by the new backend token-swap endpoint
(POST /api/v1/auth/management/users/{id}/impersonate/):

- lib/auth-token-cookie.ts: second cookie pair
  (archetype_impersonator_token) to stash the admin's original token
  while impersonating.
- contexts/auth-context.tsx: isImpersonating state plus
  startImpersonation/stopImpersonation, restored on mount and cleared
  on logout.
- services/backoffice/users.ts: impersonateUser() bespoke POST call.
- components/impersonation-banner.tsx: app-wide "Stop impersonating"
  banner mounted in the root layout, inside AuthProvider.
- app/backoffice/users/page.tsx: row action gated to non-self,
  non-staff, non-superuser targets (mirrors the backend's own
  restrictions), with a confirm dialog before switching sessions.

Includes en/fr translations and tests for the context, banner, and
page-level gating/mutation flow.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant