Skip to content

Commit 76c3846

Browse files
authored
Merge pull request #18571 from craftcms/bugfix/18569-failed-to-impersonate-with-token
Bugfix/18569 failed to impersonate with token
2 parents 02e9dba + 8efcb29 commit 76c3846

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fixed an error that could occur after running the `utils/fix-field-layout-uids` command. ([#18516](https://github.com/craftcms/cms/issues/18516))
66
- Fixed a JavaScript error that could occur if any field layout elements were configured with unsupported widths. ([#18552](https://github.com/craftcms/cms/issues/18552))
7+
- Fixed an error that could occur when user impersonation failed. ([#18569](https://github.com/craftcms/cms/issues/18569))
78

89
## 4.17.10 - 2026-03-11
910

src/controllers/UsersController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,10 @@ public function actionImpersonateWithToken(int $userId, int $prevUserId): ?Respo
378378
if (!$success) {
379379
$this->setFailFlash(Craft::t('app', 'There was a problem impersonating this user.'));
380380
Craft::error(sprintf('%s tried to impersonate userId: %s but something went wrong.',
381-
$userSession->getIdentity()->username, $userId), __METHOD__);
382-
return null;
381+
$userSession->getIdentity()?->username ?? 'Unknown user', $userId), __METHOD__);
382+
return $this->redirect($this->request->getIsCpRequest()
383+
? Request::CP_PATH_LOGIN
384+
: Craft::$app->getConfig()->getGeneral()->getLoginPath() ?? '');
383385
}
384386

385387
return $this->_handleSuccessfulLogin($user);

0 commit comments

Comments
 (0)