Modify Headers Before Authentication

Posted 3 months ago by danielcoker

I want to modify the header of an incoming request to add the authorization header. I've created a middleware already, but it's not working. Here's my code.

public function handle($request, Closure $next)
    {
        $response = $next($request);

        $response->header('Authorization', 'Bearer ' . $request->cookie('token'));

        return $response;
    }

I've also tried this, I still get the same result

public function handle($request, Closure $next)
    {
        $response = $next($request);

        $response->headers->set('Authorization', 'Bearer ' . $request->cookie('token'));

        return $response;
    }

I've also added the middleware in the kernel.

After all this, it's not still authenticating the user. Is there a way to change the headers before the user gets authenticated.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.