I am using manual authentication in Larave, here is my code function
public function doLogin(){
$userdata = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
if (Auth::attempt($userdata,true)) {
return (Auth::check() ? 'true' : 'false');
}
else {
return (Auth::check() ? 'true' : 'false');
}
}
After logging in Auth::check, true is returned. But after viewing protected routes that have this build function
public function __construct()
{
$this->middleware('auth');
}
middleware redirects me to the login page again, even after logging in.
Authmiddleware never changed. Are there any changes I need to make?
I also tried my own middleware:
class LoginCheck
{
public function handle($request, Closure $next)
{
if (!Auth::check()) {
if ($request->ajax() || $request->wantsJson()) {
return response('Unauthorized.', 401);
} else {
return redirect('login');
}
}
return $next($request);
}
}
Still not working, means that Auth :: check () returns false.
Cookies are configured to save the session and still do not work.
source
share