Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with custom middleware #91

Open
therajumandapati opened this issue Sep 3, 2024 · 1 comment
Open

Issues with custom middleware #91

therajumandapati opened this issue Sep 3, 2024 · 1 comment

Comments

@therajumandapati
Copy link

therajumandapati commented Sep 3, 2024

Similar to the issue reported in #75, I'm experiencing it as well.

Symfony\Component\HttpFoundation\Response::setContent(): Argument #1 ($content) must be of type ?string, Illuminate\Routing\Redirector given, called in [redacted]/vendor/laravel/framework/src/Illuminate/Http/Response.php on line 73

This is only happening in my case because I have a middleware.

public function handle(Request $request, Closure $next): Response
    {
	    if(!empty(auth()->user())){
		    // session value set on login
		    setPermissionsTeamId(auth()->user()->org_id);
	    }
        return $next($request);
    }

The error is triggered by the return call within this middleware. Since the Impersonator is returning a redirect response, it doesn't seem to work with the way Laravel 11 middlewares are created.

Any thoughts?

@jszobody
Copy link
Member

jszobody commented Sep 8, 2024

It's quite common for a Laravel controller method to return a redirect, that's supported and well documented. Returning a redirect works just fine with Laravel middleware, in general.

Laravel even documents returning redirects from middleware itself (which would be handled by other middleware). See the first example on https://laravel.com/docs/11.x/middleware#defining-middleware.

Something else is going on here that isn't apparent from the snippet of code you've shared. You'll need to do further debugging and troubleshooting to see what's really going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants