Skip to content

When Session based Guard is not used Logout fails #486

Closed
@karmendra

Description

@karmendra

In Fortify configuration, when I switch the middleware to "api," the logout functionality doesn't work as expected. It attempts to invalidate the session and regenerate it, but there is no session present in api middleware, and the code errors.

I suggest, to add a conditional check in the Laravel\Fortify\Http\Controllers\AuthenticatedSessionController@destroy() method, as shown below, to ensure that the session is invalidated and regenerated only when request has a session.

public function destroy(Request $request): LogoutResponse
    {
        $this->guard->logout();

       if ($request->hasSession()) { // this is the check I like to add
            $request->session()->invalidate();
            $request->session()->regenerateToken();
        }

        return app(LogoutResponse::class);
    }

I can submit a PR if it makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions