<?php
namespace Misuzu;

use Misuzu\Auth\AuthTokenCookie;

$urls = $msz->getURLs();
if(CSRF::validateRequest()) {
    $tokenInfo = $msz->getAuthInfo()->getTokenInfo();

    if($tokenInfo->hasImpersonatedUserId()) {
        $impUserId = $tokenInfo->getImpersonatedUserId();

        $tokenBuilder = $tokenInfo->toBuilder();
        $tokenBuilder->removeImpersonatedUserId();
        $tokenInfo = $tokenBuilder->toInfo();

        AuthTokenCookie::apply($tokenPacker->pack($tokenInfo));
        Tools::redirect($urls->format('manage-user', ['user' => $impUserId]));
        return;
    }
}

Tools::redirect($urls->format('index'));
