无法在 AuthenticationSuccessEvent 中获取用户 getter

Can't get User getter in AuthenticationSuccessEvent

我尝试在身份验证成功事件后保存用户 gsm 数据:

 /**
     * @param AuthenticationSuccessEvent $event
     */
    public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
    {
        $data = $event->getData();
        $user = $event->getUser();
        dd($user);
        $gsm = isset(\json_decode($this->requestStack->getCurrentRequest()->getContent())->gsm) ? \json_decode($this->requestStack->getCurrentRequest()->getContent())->gsm : null;

        if ($user->getGsm()) { // <------   get user GSM 
            ...
        } else {
            ...
        }


        $event->setData($data);
    }

当我尝试生成令牌时,它工作正常:

但是当我尝试刷新令牌时 我收到 symfony 错误:

Attempted to call an undefined method named "getGsm" of class "Symfony\Component\Security\Core\User\User".

dd($user) 的结果是:

当您实际尝试保存 GSM 数据时,您正试图在 Symfony 用户 class 上调用 getGsm 方法。

确保您使用的是正确的用户,您将需要改用 setGsm。