feat(backoffice): add user impersonation UI for admins - #108
Draft
geourjoa wants to merge 1 commit into
Draft
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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/isImpersonatingon the auth context (contexts/auth-context.tsx): stashes the admin's real token in a second cookie while impersonating, restores it on "stop".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 --noEmitcleaneslint/prettier --checkcleanNo new dependencies.
Side note (unrelated, left untouched): noticed
messages/en.json'slogin.signInkey holds French text ("Se connecter") in the English catalogue — pre-existing, out of scope here.