Skip to content

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

Closed
@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