Laravel 5.4 Auth Session destroyed after redirect to other route
Hello I am working on a project in laravel 5.4 on localhost it is working perfect but on live server there is a problem with Auth session after login when i redirect to dashboard the auth has been destroyed Here is my login code and routes
public function login(Request $request){ $fields = [ 'email' => 'required', 'password' => 'required' ]; $input = $this->validateInput($request, $fields); if($this->validation_error){ return $this->displayResponseToUser($input); }else{ if (Auth::attempt(['email' => $request['email'], 'password' => $request['password']])){ $user_id = Auth::User()->id; if(Auth::user()->role_id==3){ Session::put('company_id',$user_id); }else if(Auth::user()->role_id==2){ $user_permissions=\App\EmployeesPermissions::whereEmployeeId(Auth::user()->id)->get(); if(count($user_permissions)>0){ Session::put('company_id',Auth::user()->company_id); }else{ return response()->json([ 'logout' => [ 'type' => 'InvalidCredentialsException', 'message' => trans('messages.no_permission') ] ]); } }
$response=[
'success' => [
'type' => 'ValidCredentials',
'message' => trans('messages.logged_in_success'),
]
];
return $this->displayResponseToUser($response);
}
return response()->json([
'error' => [
'type' => 'InvalidCredentialsException',
'message' => trans('messages.invalid_credentials')
]
]);
}
}
Route::post('/verify-login', ['uses' => 'UserController@login', 'as' => 'verify_login']); Route::get('/dashboard', function () { if (!Auth::user()) { return redirect()->to('/login'); } return view('dashboard', ['header' => 'Dashboard']); });
Can anyone help?
Please or to participate in this conversation.