public function autoLogin(EntityInterface $user): ?Response
    {
        $controller = $this->getController();
        $request = $controller->request;
        $token = $request->getQuery('t');
        if (empty($token)) {
            return null;
        }

        $this->Auth->logout();
        $tokenData = $user->validateLoginToken($token, $user->getKey(), $user->getSalt());
        if (!is_array($tokenData)) {
            return null;
        }
        if (!empty($tokenData['addRememberMeCookie']) && $tokenData['addRememberMeCookie']) {
            $this->addRememberMeCookie((string)$user->id);
        }
        $userData = $user->toArray();
        $userData['user'] = $user;
        $this->Auth->setUser($userData);
        if (!empty($tokenData['url'])) {
            return $controller->redirect($tokenData['url']);
        }

        return $controller->redirect($this->getConfig('defaultRedirect'));
    }