Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel login error 'Header may not contain more than a single header, new line detected laravel login'

I am making a multi-auth custom login for clients. The login/logout works fine the first time I login, but shows this error in the second attempt

ErrorException in Response.php line 339: Header may not contain more than a single header, new line detected'

what may be the cause for this?

like image 968
Zann Avatar asked Oct 17 '22 14:10

Zann


2 Answers

you should use

return route('admin.dashboard');

instead of

 return redirect('admin/dashboard');
like image 88
Vahid Alvandi Avatar answered Oct 21 '22 06:10

Vahid Alvandi


I'm facing same issue. Watching closely, I noticed that the header that is being passed contains not just a newline char, but also html code. A code for a page just annoucing the redirection to the route I wanted it to redirect.

My login is redirectTo is

/**
 * Where to redirect users after login.
 *
 * @return string
 */
protected function redirectTo()
{
    return redirect()->route((string)\Auth::user()->group->type);
}

Where already exists a named route for each group->type possible.

I've already tried just a return to the route path with no success or any different error message.

[UPDATE] I found a fix here, changed my code to this and it worked:

protected function redirectTo()
{
    // return redirect()->route((string)\Auth::user()->group->type);
    return route(\Auth::user()->group->type);
}
like image 31
Albert Uler Silva Melo Avatar answered Oct 21 '22 05:10

Albert Uler Silva Melo