Skip to content

AuthenticationUtils::getLastUsername(): Return value must be of type string, null returned #53503

@r3dge

Description

@r3dge

Symfony version(s) affected

6.4.1

Description

In production environment i get regularly this exception in logs :

Uncaught PHP Exception TypeError: "Symfony\Component\Security\Http\Authentication\AuthenticationUtils::getLastUsername(): Return value must be of type string, null returned" at AuthenticationUtils.php

How to reproduce

I don't know exactly what trigger this exception

Possible Solution

Changing the return type of the method :

public function getLastUsername(): ?string
{
$request = $this->getRequest();

    if ($request->attributes->has(SecurityRequestAttributes::LAST_USERNAME)) {
        return $request->attributes->get(SecurityRequestAttributes::LAST_USERNAME, '');
    }

    return $request->hasSession() ? $request->getSession()->get(SecurityRequestAttributes::LAST_USERNAME, '') : '';
}

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy