Skip to content

Commit 4f7fc96

Browse files
committed
fix(webapp): reset the view-as-user flag when switching impersonation target
The flag is scoped to a single impersonation session, which is why stopping impersonation drops it. Switching straight from one target to another only became possible in this branch, and that path sets the impersonated id without touching the flag, so an admin viewing target A as the user landed on target B with the toggle still on. It is now cleared whenever the target changes.
1 parent f1c6eb3 commit 4f7fc96

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

apps/webapp/app/services/impersonation.server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export async function getImpersonationId(request: Request) {
4545
export async function setImpersonationId(userId: string, request: Request) {
4646
const session = await getImpersonationSession(request);
4747

48+
// Switching straight to a different target begins a new impersonation session, so the view-as-user
49+
// flag must not carry over from the previous one — it's scoped to a single impersonation, which is
50+
// why `clearImpersonationId` drops it too. Reachable only since switching stopped requiring a stop
51+
// first; before that, every second target arrived via `clearImpersonationId`.
52+
if (session.get(IMPERSONATED_USER_ID_KEY) !== userId) {
53+
session.unset(VIEWING_AS_USER_KEY);
54+
}
55+
4856
session.set(IMPERSONATED_USER_ID_KEY, userId);
4957

5058
return session;

0 commit comments

Comments
 (0)