Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions apps/webapp/app/services/session.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ import { getImpersonationId } from "./impersonation.server";
export async function getUserId(request: Request): Promise<string | undefined> {
const impersonatedUserId = await getImpersonationId(request);

if (impersonatedUserId) return impersonatedUserId;
if (impersonatedUserId) {
// Verify the real user (from the session cookie) is still an admin
const authUser = await authenticator.isAuthenticated(request);
if (authUser?.userId) {
const realUser = await getUserById(authUser.userId);
if (realUser?.admin) {
return impersonatedUserId;
}
}
// Admin revoked or session invalid — fall through to return the real user's ID
return authUser?.userId;
}

let authUser = await authenticator.isAuthenticated(request);
return authUser?.userId;
Expand Down Expand Up @@ -54,7 +65,7 @@ export async function requireUser(request: Request) {
dashboardPreferences: user.dashboardPreferences,
confirmedBasicDetails: user.confirmedBasicDetails,
mfaEnabledAt: user.mfaEnabledAt,
isImpersonating: !!impersonationId,
isImpersonating: !!impersonationId && impersonationId === userId,
};
}

Expand Down
Loading