fix: impersonation navigation uses full page reload
All checks were successful
Build and Push Docker Image / build (push) Successful in 9m59s

Replace router.push() with window.location.href for both
start and end impersonation to ensure the updated JWT cookie
is sent with the new request. Client-side routing can race
with cookie propagation, causing the server to see the old
session and redirect back to admin.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 20:30:46 +01:00
parent 27ecbc40b3
commit ca888b4eb7
2 changed files with 6 additions and 9 deletions

View File

@@ -126,9 +126,9 @@ export function UserActions({ userId, userEmail, userStatus, userRole, userRoles
try { try {
const result = await startImpersonation.mutateAsync({ targetUserId: userId }) const result = await startImpersonation.mutateAsync({ targetUserId: userId })
await update({ impersonate: userId }) await update({ impersonate: userId })
toast.success(`Now impersonating ${userEmail}`) // Full page navigation to ensure the updated JWT cookie is sent
router.push(getRoleHomePath(result.targetRole) as Route) // (router.push can race with cookie propagation)
router.refresh() window.location.href = getRoleHomePath(result.targetRole)
} catch (error) { } catch (error) {
toast.error(error instanceof Error ? error.message : 'Failed to start impersonation') toast.error(error instanceof Error ? error.message : 'Failed to start impersonation')
} }
@@ -302,9 +302,7 @@ export function UserMobileActions({
try { try {
const result = await startImpersonation.mutateAsync({ targetUserId: userId }) const result = await startImpersonation.mutateAsync({ targetUserId: userId })
await update({ impersonate: userId }) await update({ impersonate: userId })
toast.success(`Now impersonating ${userEmail}`) window.location.href = getRoleHomePath(result.targetRole)
router.push(getRoleHomePath(result.targetRole) as Route)
router.refresh()
} catch (error) { } catch (error) {
toast.error(error instanceof Error ? error.message : 'Failed to start impersonation') toast.error(error instanceof Error ? error.message : 'Failed to start impersonation')
} }

View File

@@ -18,9 +18,8 @@ export function ImpersonationBanner() {
try { try {
await endImpersonation.mutateAsync() await endImpersonation.mutateAsync()
await update({ endImpersonation: true }) await update({ endImpersonation: true })
toast.success('Returned to admin account') // Full page navigation to ensure updated JWT cookie is sent
router.push('/admin/members') window.location.href = '/admin/members'
router.refresh()
} catch (error) { } catch (error) {
toast.error(error instanceof Error ? error.message : 'Failed to end impersonation') toast.error(error instanceof Error ? error.message : 'Failed to end impersonation')
} }